const ball = { x: 200, y: 200, size: 0, speed: 1, }; function setup() { createCanvas(400, 400); } function draw() { background(255); strokeWeight(2); fill(ball.size, 0, 0); star(ball.x, ball.y, 100, ball.size, 5); ball.size += ball.speed; ball.speed *= 1.5; if (ball.size >= 200) { ball.size = 200; ball.speed = -1; } if (ball.size <= 0) { ball.size = 0; ball.speed = 1; } } function star(x, y, radius1, radius2, npoints) { let angle = TWO_PI / npoints; let halfAngle = angle / 2.0; beginShape(); for (let a = 0; a < TWO_PI; a += angle) { let sx = x + cos(a) * radius2; let sy = y + sin(a) * radius2; vertex(sx, sy); sx = x + cos(a + halfAngle) * radius1; sy = y + sin(a + halfAngle) * radius1; vertex(sx, sy); } endShape(CLOSE); }