Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // The colors we'll be using
- color red = color(255,0,0);
- color green = color(0,255,0);
- color blue = color(0,0,255);
- // Winning color and it's hue
- int winHue = 0;
- color winColor;
- // Index to pick colors from
- color[] colors = new color[]{red, green,blue};
- // Each quadrant's color value index
- int[] quadrants = new int[4];
- int midX;
- int midY;
- boolean won;
- void setup() {
- // Set size of the canvas
- size(800, 600);
- println(midX);
- println(midY);
- // Set each our quadrants to a random color
- // Red, Green or Blue
- quadrants[0] = int(random(3));
- quadrants[1] = int(random(3));
- quadrants[2] = int(random(3));
- quadrants[3] = int(random(3));
- // Set midX and midY
- midX = width/2;
- midY = height/2;
- won = false;
- }
- void win() {
- colorMode(HSB,255,100,100);
- background(color(winHue++ % 255,100,100));
- println(winHue);
- }
- void draw() {
- if (!won) {
- // Bulding each quadrant
- //Quadrant 1
- fill(colors[quadrants[0]]);
- rect(0,0,width/2,height/2);
- //Quadrant 2
- fill(colors[quadrants[1]]);
- rect(0,height/2,width/2,height/2);
- //Quadrant 3
- fill(colors[quadrants[2]]);
- rect(width/2,0,width/2,height/2);
- //Quadrant 4
- fill(colors[quadrants[3]]);
- rect(width/2,height/2,width/2,height/2);
- } else {
- win();
- }
- }
- void mouseClicked() {
- if (!won) {
- if (mouseX < midX && mouseY < midY) {
- quadrants[0] = ++quadrants[0] % 3;
- } else if(mouseX < midX && mouseY > midY) {
- quadrants[1] = ++quadrants[1] % 3;
- } else if(mouseX > midX && mouseY < midY) {
- quadrants[2] = ++quadrants[2] % 3;
- } else {
- quadrants[3] = ++quadrants[3] % 3;
- }
- if (quadrants[0] == quadrants[1] &&
- quadrants[0] == quadrants[2] &&
- quadrants[0] == quadrants[3]) {
- won = true;
- }
- }
- }
Add Comment
Please, Sign In to add comment