copy(0, 0, width, height, -step, -step, width + step * 2, height + step * 2);
randomSeed(frameCount / 100);
let x, y, xMin, yMin, xMax, yMax, xStep, yStep;
yStep = random((yMax - yMin) / 25, (yMax - yMin) / 3);
if (y + yStep > yMax || yMax - (y + yStep) < (yMax - yMin) / 20) {
xStep = random((xMax - xMin) / 25, (xMax - xMin) / 3);
if (x + xStep > xMax || xMax - (x + xStep) < (xMax - xMin) / 20) {
drawOsc(x, y, xStep, yStep);
function drawOsc(x, y, w, h) {
let wave_type = int(random(7));
let freq = random(0.25, 4);
fill(getColorByTheta((n + rn) / 10000, frameCount / 100, freq * 5 * sin(rn + frameCount / 100)));
let v = osc(n + rn, wave_type) * sin((x + y * width + n) / 50 + frameCount / 15);
function osc(x, n = -1) {
v = round(sin(-x * .1)) * .25;
v = abs(sin(x * .1)) * .5;
v = abs(sin(x * .01 + x * .1)) * .5;
v = (x * .025) % 1 < .5 ? -.5 : .5;
v = ceil(sin(x * .1)) * .25;
v = sin(x * .1) * cos(x * 1) * .5;
function getColorByTheta(theta, time, freq) {
let th = freq * theta + time * freq;
let r = 0.5 + 0.5 * sin(th);
g = 0.5 + 0.5 * sin(th - PI * 1 / 3);
b = 0.5 + 0.5 * sin(th - PI * 2 / 3);
return color(r * 255, g * 255, b * 255);