Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //static variables
- color yellow = color(239, 255, 23);
- color gray = color(195, 196, 192);
- //"instance" variables
- boolean[][] grid;
- int boxWidth, boxHeight;
- void setup() {
- size(500, 500);
- background(gray);
- initGrid();
- drawLines();
- }
- void draw() {
- if (mousePressed == true) {
- changeElement();
- delay(100);
- }
- //drawGrid(); //to be completed day 2
- if(keyCode == ENTER){
- frameRate(5);
- //update(); //to be completed day 2
- }
- else if(keyCode == CONTROL){
- keyCode = SHIFT;
- initGrid();
- frameRate(60);
- }
- }
- void changeElement() {
- grid[mouseX/boxWidth][mouseY/boxHeight] = !grid[mouseX/boxWidth][mouseY/boxHeight];
- }
- //*********************//
- // DAY 1 //
- //*********************//
- //1. void initGrid()
- //a) instantiate the grid to be 50 by 50. *Note: This will also initialize all elements to false, which is what we want.
- //b) initialize the boxWidth and boxHeight to be the width and height divided by the number of boxes in each row
- void initGrid() {
- }
- //2. void drawLines()
- //* remember, the line function works like line(x1, y1, x2, y2);
- //a) draw all lines going across from left to right
- //b) draw all lines going vertically from top to bottom
- //c) each line should be separated by boxWidth or boxHeight in either direction
- //*there should be 50 lines in either direction
- //*height and width are variables that contain the height and width, respectively
- void drawLines() {
- }
- //3. int countNeighbors(int r, int c)
- //This method takes the row number and column number and returns the number of neighbors @ that location
- //a) initialize a counter
- //b)check all 8 neighbors and increment counter if they are populated ( true )
- //b1) check the 3 elements in the row above
- //b2) check the 2 elements in the same row to the left or right.
- //b3) check the 3 elements in the row below
- //*be careful about bounds issues. For example, if r = 0, the row above would be -1, which does not exist and will cause an error
- //c) return the count
- int countNeighbors(int r, int c) {
- //get rid of the line below and write the method
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement