Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int
- y, // joint height of the figures
- squareX, // x of the square
- circleX, // x of the circle
- size, // joint size (diameter) of the figures
- squareColor = 0, // square color
- circleColor = 255, // circle color
- baseColor = 100; // background color
- void setup() {
- size(1280, 745);
- rectMode (CENTER);
- size = height / 4;
- y = height / 2;
- squareX = width / 2 - size;
- circleX = width / 2 + size;
- }
- void draw() {
- // background
- if (overSquare())
- background(squareColor);
- else if (overCircle())
- background(circleColor);
- else
- background(baseColor);
- // square
- stroke(circleColor);
- fill(squareColor);
- square(squareX, y, size);
- // circle
- stroke(squareColor);
- fill(circleColor);
- circle(circleX, y, size);
- }
- boolean overSquare ( ) {
- int radius = size/2;
- if (mouseX >= squareX - radius && mouseX <= squareX + radius
- &&
- mouseY >= y - radius && mouseY <= y + radius
- )
- return true;
- else
- return false;
- }
- boolean overCircle ( ) {
- if (sqrt(sq(circleX - mouseX) + sq(y - mouseY)) < size/2)
- return true;
- else
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement