int mapsx = 100; //Set the dimension of the 2D array int mapsy = 100; //Declaration of the 2D array. It is of type Pixel, a class that we are about to make up Pixel map[][] = new Pixel[mapsx][mapsy]; //Behold, the glorious Pixel class. It just stores 3 integers for red, green, and blue class Pixel { int r, g, b; Pixel(int a, int b, int c) { this.r = a; this.g = b; this.b = c; } } void setup () { noStroke(); //Get rid of border outlines for our rectangles size(500, 500); for (int i = 0; i < mapsx; i++) {//For every row for (int j = 0; j < mapsy; j++) {//Do an entire column //This is what the initialization might look like if we used only integers //map[i][j] = floor(random(255)); //Random values 0 - 255 //map[i][j] = 0; //Blank slate //This is what it looks like for Pixels. //We are just using the constructor we defined above. //map[i][j] = new Pixel(floor(random(255)),floor(random(255)),floor(random(255))); map[i][j] = new Pixel(0, 0, 0); //All black } } } //Finish this function so that provided x,y and a size //it will update the 2D grid values at x,y in a square of size : size //Example 10,19 size 8 will make an 8 by 8 size set of pixels on the grid with // top left corner 10, 15 //Example syntax //block(10, 19, 8, new Pixel(175, 0, floor(random(255)))); //Random colour void block(int x, int y, int size, Pixel col) { //println(x + " " + y + " " + size + " " + col.r + " " + col.g + " " + col.b); } void draw() { for (int i = 0; i < mapsx; i++) { for (int j = 0; j < mapsy; j++) { fill(map[i][j].r, map[i][j].g, map[i][j].b); //Use the 2D array to get the colour rect(i * 5, j * 5, 5, 5); //Draw it! } } } //This is an airbrush style version of block, however it assumes the 2D grid is of type Integer //It will need an updrage to make it work with Pixels void disperse(int x, int y, int s, float in, int[][] map) { map[x][y] += in; if (map[x][y] > 255) map[x][y] = 255; for (int i= x - s; i < x + s; i++) { for (int j= y - s; j < y + s; j++) { if (dist(i, j, x, y) <= s && i >= 0 && i < mapsx && j >= 0 && j < mapsy && !(i == x && j == y)) { map[i][j] += in * ((float)s / dist(i, j, x, y)); if (map[i][j] > 255) map[i][j] = 255; } } } } void mousePressed() { block(30, 25, 8, new Pixel(0, 0, 0)); }