Skip to content

Instantly share code, notes, and snippets.

@claytical
Created September 7, 2015 18:43
Show Gist options
  • Save claytical/1078549d5469782b2432 to your computer and use it in GitHub Desktop.
Save claytical/1078549d5469782b2432 to your computer and use it in GitHub Desktop.
p5js event functions
function setup() {
// uncomment this line to make the canvas the full size of the window
createCanvas(windowWidth, windowHeight);
}
function draw() {
}
function keyPressed() {
//draw a diagonal line starting from top left corner
line(0, 0, width, height);
}
function keyReleased() {
//draw a diagonal line starting from the top right corner
line(width, 0, 0, height);
}
function mousePressed() {
ellipse(width/2, 20, 20, 20);
}
function mouseReleased() {
ellipse(width/2, height-20, 20, 20);
}
function mouseMoved() {
line(mouseX, mouseY, pmouseX, pmouseY);
}
function mouseDragged() {
rect(mouseX, mouseY, 10, 10);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment