xxxxxxxxxx
130
//(C) TIMOTHY KELLY 2021
let speed = 1;
var no;
let targetX = [];
let targetY = [];
let t = 1;
var x = [];
var y = [];
var w = [];
var h = [];
const colors = ['#fff100','#ff8c00','#e81123','#ec008c','#68217a','#00188f','#00bcf2','#00b294','#009e49','#bad80a'];
var c = [];
var bg;
var greyscale;
function setup() {
createCanvas(windowWidth, windowHeight);
frameRate(30);
no = random(5,10);
greyscale = boolean(Math.random() < 0.5);
for (var i = 1; i <= no; i++){
targetX[i] = parseInt(random(-width/2,width/2));
targetY[i] = parseInt(random(-height/2,height/2));
x[i] = parseInt(random(-width/2,width/2));
y[i] = parseInt(random(-height/2,height/2));
h[i] = height/4;
w[i] = width/4;
if (greyscale){
c[i] = 255
}else{
c[i] = colors[int(random(colors.length))];}
}
var cL = colors.length;
var bgC = int(random(colors.length));
bg = colors[bgC];
if (greyscale) {
background(255);
} else {
background(hexToRgb(bg).r,hexToRgb(bg).g,hexToRgb(bg).b);
}
}
function draw() {
if (frameCount %30 == 0){
if(greyscale){
background(255,4);
} else{
background(hexToRgb(bg).r,hexToRgb(bg).g,hexToRgb(bg).b,1);}
}
noFill();
rectMode(CENTER);
for (var i = 1; i <= no; i++) {
w[i] = noise(t+i)*width/2;
h[i] = noise(t+i)*width/2;
push();
translate(x[i],y[i]);
translate(width/2,height/2);
rotate(radians(frameCount+(i*20)));
translate(-width/2,-height/2);
var wT = w[i]/50
stroke(0);
strokeWeight((w[i]/25)+2);
rect(width/2,height/2,w[i],h[i]);
strokeWeight((w[i]/50));
stroke(c[i]);
rect(width/2,height/2,w[i],h[i]);
pop();
if (x[i] < targetX[i]-1){
x[i]+=1;
} else if (x[i] > targetX[i]-1){
x[i]=x[i]-1;
} else if (y[i] < targetY[i]-1){
y[i]+=1;
} else if (y[i] > targetY[i]+1){
y[i]=y[i]-1;
} else {
x[i]+=1;
y[i]+=1;
targetX[i] = int(random(-width/2,width/2));
targetY[i] = int(random(-height/2,height/2));
print("new target (" + i + ")");
}
}
t+=0.05
}
function mousePressed(){
setup();
}
function hexToRgb(hex) {
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
return result ? {
r: parseInt(result[1], 16),
g: parseInt(result[2], 16),
b: parseInt(result[3], 16)
} : null;
}