xxxxxxxxxx
34
let angle = 0;
let speed = 2;
function setup() {
createCanvas(400, 400);
angleMode(DEGREES);
}
function draw() {
background(255);
//draw the shape of the metronome
strokeWeight(5);
fill(255);
quad(175,100,225,100,275,300,125,300);
fill(0);
triangle(180,95,220,95,200,80);
rect(198,100,5,200);
quad(275,300,125,300,145,240,255,240);
rect(140,300,10,10);
rect(250,300,10,10);
//draw the leg and make it rotate back and forth
translate(200,240);
rotate(angle);
line(0,0,0,-120);
angle = angle+speed;
if (angle==60){
speed = speed * -1;
}
if (angle==-60){
speed = speed * -1;
}
}