noFill confusion
in
Programming Questions
•
3 years ago
- //EXC 19_5
- //this is the size of each sheild unit, the smaller, the more difficult to uncover
- int sheild = 20;
- //this is the length of the uncover array, the bigger the number the easier to uncover the sheild
- int strength = 20;
- //this stops the sheild loop when a matching mouseX/Y position in the uncover array is detected
- int matches = 0;
- //this is the uncover array, it stores the last x mouse positions, and removes the sheild from those points
- int[] uncoverX = new int[strength];
- int[] uncoverY = new int[strength];
- //this increments the uncover array
- int inc = 0;
- Token[] square = new Token[4];
- int score = 0;
- void setup(){
- size(600,400);
- smooth();
- background(255);
- for(int i = 0; i < 4; i++){
- square[i] = new Token();
- }//close for loop
- }//close setup
- void draw(){
- background(255);
- for(int i = 0; i < 4; i++){
- square[i].display();
- }//close for loop
- //cover the board with the sheild
- for(int i = 0; i < width; i = i+sheild){
- for(int j = 0; j < height; j = j+sheild){
- matches = 0;
- //check where sheild and uncover array overlap
- for(int q = 0; q < strength; q++){
- if( (uncoverX[q] >= i && uncoverX[q] <= i + sheild) && (uncoverY[q] >= j && uncoverY[q] <= j + sheild) ){
- //fill(255); //This works like I expect noFill() should work...
- noFill();
- rect(i , j, sheild, sheild);
- matches = 1;
- }
- else if(matches != 1 ){
- fill(0,255,0);
- rect(i , j, sheild, sheild);
- } //close if
- }//close if
- }//close j loop
- }//close i loop
- }//close draw
- void mouseClicked(){
- println( "(x, y) = " + "(" + mouseX + "," + mouseY + ")" );
- for(int i = 0; i < 4; i++){
- square[i].clicked();
- }//close for loop
- }//close mouseClicked
- void mouseMoved(){
- uncoverX[inc] = mouseX;
- uncoverY[inc] = mouseY;
- inc += 1;
- if(inc > strength - 1){
- inc = 0;
- }//close if
- }//close mouseMoved
- //this is the class that is the shape you press
- class Token{
- //tracks if the Token has been clicked
- int clicked;
- //these variable assign a size to the rect
- int rectWidth;
- int rectHeight;
- //these variables give a random location to the rect
- int varWidth;
- int varHeight;
- color c;
- //these variables set the bounds for the mouse button
- int leftLimit;
- int rightLimit;
- int topLimit;
- int bottomLimit;
- Token(){
- //tracks if the Token has been clicked
- clicked = 0;
- //these variable assign a size to the rect
- rectWidth = 20;
- rectHeight = 20;
- //these variables give a random location to the rect
- varWidth = int(random(20, width - 20));
- varHeight = int(random(20, height - 20));
- c = color(255,0,0);
- //these variables set the bounds for the mouse button
- leftLimit = varWidth;
- rightLimit = varWidth + rectWidth;
- topLimit = varHeight;
- bottomLimit = varHeight + rectHeight;
- }//close constructor
- void display(){
- //rect attributes
- fill(c);
- noStroke();
- //display a rectangle
- rect(varWidth, varHeight, rectWidth, rectHeight);
- }//close display
- //Make a mouse over
- void clicked(){
- if(leftLimit < mouseX && mouseX < rightLimit && topLimit < mouseY && mouseY < bottomLimit && clicked == 0){
- // stroke(255);
- c = color(255);
- score += 1;
- println("Your Score = " + score);
- clicked = 1;
- }//close if
- }//close clicked
- }//close Token class
1