xxxxxxxxxx
25
let angleRotate = 5; // an variable for angle
let R = 100; // R is red in RGB for changing color
let originX = 200;
let originY = 200;
let colorCoe = 1; // color coefficient
function setup() {
createCanvas(originX * 2, originY * 2);
angleMode(DEGREES);
}
function draw() {
background(220);
stroke("black");
strokeWeight(2);
fill(R, 255, 255);
translate(originX, originY); // move the origin to the center
rotate(angleRotate); // let the shape rotate
rect(0,0,100,100); // the shape rotates around the origin
angleRotate += 1; // increase a degree after every loop
R += colorCoe*1;
// the colorCoe will change when R reaches 255 or 100
if (R === 255 || R === 100) colorCoe *= -1;
}