xxxxxxxxxx
47
function setup() {
createCanvas(720, 400);
}
function draw() {
background(102);
push();
if (mouseIsPressed) {
fill(mouseX, 0, mouseY) }
translate(width * 0.2, height * 0.5);
rotate(frameCount / mouseX);
star(0, 0, 5, 70, 3);
pop();
push();
if (mouseIsPressed) {
fill(mouseY,mouseX,0) }
translate(width * 0.5, height * 0.5);
rotate(frameCount / 50.0);
star(0, 0, 80, mouseY-100, 40);
pop();
push();
if (mouseIsPressed) {
fill(0, mouseY, mouseX) }
translate(width * 0.8, height * 0.5);
rotate(frameCount / -mouseY);
star(0, 0, 30, 70, 5);
pop();
}
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);
}