-
Notifications
You must be signed in to change notification settings - Fork 0
Getting Started
Aaron Echler edited this page Feb 19, 2024
·
5 revisions
function setup() {
createCanvas(400, 400);
rectMode(CENTER);
angleMode(DEGREES);
}
function draw() {
background(0);
translate(width/2, height/2);
rotate(50);
rect(width/2, height/2, 100, 50);
}
- Get the distance from a point.
function draw() {
background(220);
let distance = dist(mouseX, mouseY, width/2, height/2);
translate(width/2, height/2);
if(distance < distMouse){
angle+=1;
}
rotate(angle);
rect(0, 0, 100, 50);
}
- You can access the previous mouse position compared to the current one.
function setup() {
createCanvas(400, 400);
background(255);
}
function draw() {
stroke(0);
if (mouseIsPressed) {
line(mouseX, mouseY, pmouseX, pmouseY);
}
}