xxxxxxxxxx
39
// setting a variable for the angle of rotation
let angle = 0;
let angle_change = 1;
function setup() {
createCanvas(400, 400);
rectMode(CENTER); // this line will make the (x,y) coordinate of the rectangle be the center (not the top left corner)
angleMode(DEGREES);
}
function draw() {
background(50);
// adding one to the angle of rotation
if (mouseIsPressed == true) {
angle = angle + angle_change;
}
if (angle > 60) {
angle_change = angle_change * -1;
}
if (angle < 0) {
angle_change = angle_change * -1;
}
push(); // starting the transformation
translate(200, 200); // setting the point of rotation to 200, 200
rotate(angle); // using the variable angle in rotate
fill(255);
noStroke();
rect(0,0, 100, 100);
pop(); // ending the rotation
}