xxxxxxxxxx
40
function setup() {
createCanvas(400, 400);
background(220);
frameRate(40); //frameRate() is a function
//print(frameRate()); //it takes a while for the frame rate to change
//can't have two setup funcctions, only draws the last one
//probably because things get overwritten
}
function draw() {
//background(220);
//print(frameRate());//only makes sense and works properly in draw
//can't have two draw functions, it will only draw the second
//print(frameCount);//variable that stores which frame we are currently on
// if ((frameCount % 3) == 0) {// % is the DIV function i.e. gives the remainder; == is the conditional test for equality;
// background(0);
// } else{
// background(255);
//}
// if ((mouseIsPressed)&&(mouseY < height/2)) {//===true not required because mouseIsPressed is already boolean
// background('red');
// } else {
// background('green');
// }
fill(255)
ellipse(40,40,70,70);
fill(0);//black pen colour
strokeWeight(2);//thicker lines
//print(frameRate());
let distance = pow(pow(mouseX - 40,2)+pow(mouseY - 40,2),0.5);//calculating the distance of the cursor from the center of the button//easier to use dist function
if (mouseIsPressed === true) {
line(mouseX,mouseY,pmouseX,pmouseY);
if (distance < 35) {
background(220);
}
}
// print(distance)
}