xxxxxxxxxx
63
// tried a few ways this was the simplest
// algorithm
// if row and column are both even place a dot
// else if row and colum are both odd place a dot
let sz;
let nob = 8; // number of balls
let offset;
let theta=0
let szspeed =-5
let acc =2
function setup() {
createCanvas(800, 800);
sz = width / nob;
background(0);
fill(0);
noStroke();
frameRate(2)
angleMode(DEGREES)
nob = 40;
//sz = 5;
offset = 20;
}
function draw() {
background(255, 255, 0);
//translate(width/2,height/2)
sz =5
// let szspeed = (map(sin(theta),-1,1,-3,3));
if (szspeed >5 ||szspeed <-5) acc *=-1
for (let col = 0; col < nob + 1; col += 1) {
if (sz > 21 || sz <3) szspeed *= -1;
sz+= szspeed
for (let row = 0; row < nob + 1; row += 1) {
// an ellipse every even row and even column
if (row % 2 == 0 && col % 2 == 0) {
ellipse(col * offset, row * offset, sz, sz);
}
// an ellipse at odd row and odd column
else if (row % 2 == 1 && col % 2 == 1) {
ellipse(col * offset, row * offset, sz, sz );
}
}
}
// theta+=1
// theta = theta%360
szspeed+=acc
}
function keyPressed() {
if (key === 'g') {
saveGif('kusama', 12);
}
if (key === 's') {
saveCanvas('kusama', 'jpg');
}
}