Guest User

Untitled

a guest
Oct 19th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. // The colors we'll be using
  2. color red = color(255,0,0);
  3. color green = color(0,255,0);
  4. color blue = color(0,0,255);
  5.  
  6. // Winning color and it's hue
  7. int winHue = 0;
  8. color winColor;
  9.  
  10. // Index to pick colors from
  11. color[] colors = new color[]{red, green,blue};
  12.  
  13. // Each quadrant's color value index
  14. int[] quadrants = new int[4];
  15.  
  16. int midX;
  17. int midY;
  18.  
  19. boolean won;
  20.  
  21. void setup() {
  22. // Set size of the canvas
  23. size(800, 600);
  24. println(midX);
  25. println(midY);
  26. // Set each our quadrants to a random color
  27. // Red, Green or Blue
  28. quadrants[0] = int(random(3));
  29. quadrants[1] = int(random(3));
  30. quadrants[2] = int(random(3));
  31. quadrants[3] = int(random(3));
  32.  
  33. // Set midX and midY
  34. midX = width/2;
  35. midY = height/2;
  36.  
  37. won = false;
  38. }
  39.  
  40. void win() {
  41. colorMode(HSB,255,100,100);
  42. background(color(winHue++ % 255,100,100));
  43. println(winHue);
  44. }
  45.  
  46. void draw() {
  47. if (!won) {
  48. // Bulding each quadrant
  49. //Quadrant 1
  50. fill(colors[quadrants[0]]);
  51. rect(0,0,width/2,height/2);
  52.  
  53. //Quadrant 2
  54. fill(colors[quadrants[1]]);
  55. rect(0,height/2,width/2,height/2);
  56.  
  57. //Quadrant 3
  58. fill(colors[quadrants[2]]);
  59. rect(width/2,0,width/2,height/2);
  60.  
  61. //Quadrant 4
  62. fill(colors[quadrants[3]]);
  63. rect(width/2,height/2,width/2,height/2);
  64. } else {
  65. win();
  66. }
  67. }
  68.  
  69. void mouseClicked() {
  70. if (!won) {
  71. if (mouseX < midX && mouseY < midY) {
  72. quadrants[0] = ++quadrants[0] % 3;
  73. } else if(mouseX < midX && mouseY > midY) {
  74. quadrants[1] = ++quadrants[1] % 3;
  75. } else if(mouseX > midX && mouseY < midY) {
  76. quadrants[2] = ++quadrants[2] % 3;
  77. } else {
  78. quadrants[3] = ++quadrants[3] % 3;
  79. }
  80. if (quadrants[0] == quadrants[1] &&
  81. quadrants[0] == quadrants[2] &&
  82. quadrants[0] == quadrants[3]) {
  83. won = true;
  84. }
  85. }
  86. }
Add Comment
Please, Sign In to add comment