====== Brendan Surprising Space: Movement ====== [[Brendan-Hsu|Brendan Hsu]] //https://p5js.org/zh-Hans/examples/form-star.html function setup() { createCanvas(1920, 1080); } //https://p5js.org/zh-Hans/examples/form-star.html function star(x, y, radius1, radius2, npoints) { translate(x, y); translate(x, y); translate(x, y); let rotateDirection = 1; if (x > 250) {rotateDirection = -1} rotate(frameCount / 10.1 * rotateDirection); let angle = TWO_PI / npoints; let halfAngle = angle / 8.0; if (x < 300) { fill("blue"); } else { fill("red"); } 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); resetMatrix(); } function sleepOrNot(time) { if (time == "x" || time == "y") { return "radius1"; } else { return "radius2!"; } } function draw() { background("rgb(0,0,0)"); fill("rgb(255,0,240)"); star(300,100, 30, 70, 5); star(90, 100, 30, 70, 5); }