90
edits
Line 46: | Line 46: | ||
rect (450,320, 100,100); | rect (450,320, 100,100); | ||
} | |||
Line 52: | Line 52: | ||
void setup() { | void setup() { | ||
size(900, 600); | size(900, 600); | ||
background(216,124,124); | background(216,124,124); | ||
Line 58: | Line 60: | ||
void draw() { | void draw() { | ||
variableRect(mouseX, mouseY, pmouseX, pmouseY); | variableRect(mouseX, mouseY, pmouseX, pmouseY); | ||
} | } | ||
//abs() calculates the absolute value (magnitude) of a number. The absolute value of a number is always positive | //abs() calculates the absolute value (magnitude) of a number. The absolute value of a number is always positive | ||
// and draws a small rectangle if the mouse is moving slowly | // and draws a small rectangle if the mouse is moving slowly | ||
// and draws a large rectangle if the mouse is moving quickly | // and draws a large rectangle if the mouse is moving quickly | ||
// random(255) calls the random colours from 0-255 for the different squares | // random(255) calls the random colours from 0-255 for the different squares | ||
//working with opacity to show layering | //working with opacity to show layering | ||
void variableRect(int x, int y, int px, int py) { | void variableRect(int x, int y, int px, int py) { | ||
float speed = abs(x-px) + abs(y-py); | float speed = abs(x-px) + abs(y-py); | ||
stroke(0); | stroke(0); | ||
fill(random(255),random(255),random(255), 190); | fill(random(255),random(255),random(255), 190); | ||
rect(x, y, speed, speed); | rect(x, y, speed, speed); | ||
} | } |
edits