xxxxxxxxxx
63
let order;
let period;
let jumps;
function setup() {
createCanvas(600,600);
makeSystem();
}
function makeSystem()
{
order = int(random(4,8));
jumps = [];
for( let idx = 0; idx < order; ++idx ) {
jumps.push( idx );
}
for( let idx = 0; idx < 1000; ++idx ) {
let a = int(random(order));
let b = int(random(order));
let tmp = jumps[a];
jumps[a] = jumps[b];
jumps[b] = tmp;
}
period = 300;
}
function draw() {
background(255);
strokeWeight(1);
stroke(0);
let t = (frameCount % period) / period;
let sep = 3.5;
for (let idx = 0; idx < order; ++idx) {
push();
translate(width / 2, height / 2);
scale(2.4);
rotate((idx * PI) / order);
rotate(lerp(0, ((jumps[idx]-idx) * PI) / order, t));
stroke(0);
for (let x = sep / 2; x < width; x += sep) {
line(x, -height, x, height);
line(-x, -height, -x, height);
}
pop();
}
}
function keyPressed() {
if( key == ' ' ) {
makeSystem();
} else if (key == "g") {
saveGif("output", period, { units: "frames", delay: 0 });
}
}