Advertisement
Nojus_Globys

black & white

Nov 22nd, 2022
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.21 KB | Software | 0 0
  1. int
  2.     y, // joint height of the figures
  3.     squareX, // x of the square
  4.     circleX, // x of the circle
  5.     size, // joint size (diameter) of the figures
  6.     squareColor = 0, // square color
  7.     circleColor = 255, // circle color
  8.     baseColor = 100; // background color
  9.  
  10. void setup() {
  11.     size(1280, 745);
  12.     rectMode (CENTER);
  13.    
  14.     size = height / 4;
  15.     y = height / 2;
  16.     squareX = width / 2 - size;
  17.     circleX = width / 2 + size;
  18. }
  19.  
  20. void draw() {
  21.     // background
  22.     if (overSquare())
  23.         background(squareColor);
  24.     else if (overCircle())
  25.         background(circleColor);
  26.     else
  27.         background(baseColor);
  28.  
  29.     // square
  30.     stroke(circleColor);
  31.     fill(squareColor);
  32.     square(squareX, y, size);
  33.    
  34.     // circle
  35.     stroke(squareColor);
  36.     fill(circleColor);
  37.     circle(circleX, y, size);
  38. }
  39.  
  40. boolean overSquare ( ) {
  41.     int radius = size/2;
  42.     if (mouseX >= squareX - radius && mouseX <= squareX + radius
  43.         &&
  44.         mouseY >= y - radius && mouseY <= y + radius    
  45.     )
  46.         return true;
  47.     else
  48.         return false;
  49. }
  50.  
  51. boolean overCircle ( ) {
  52.     if (sqrt(sq(circleX - mouseX) + sq(y - mouseY)) < size/2)
  53.         return true;
  54.     else
  55.         return false;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement