SHOW:
|
|
- or go back to the newest paste.
1 | //create a random two color block, define block sizes, number of rows, numbers of columns, define colors | |
2 | //coded in Processing | |
3 | //by fbz | |
4 | ||
5 | ||
6 | Cell[][] grid; | |
7 | ||
8 | int numPixels; | |
9 | int blockSize = 4; | |
10 | int cols = 10; | |
11 | int rows = 4; | |
12 | ||
13 | ||
14 | void setup() { | |
15 | noLoop(); | |
16 | size(cols*blockSize,rows*blockSize); | |
17 | grid = new Cell[cols][rows]; | |
18 | for (int i = 0; i < cols; i++) { | |
19 | for (int j = 0; j < rows; j++) { | |
20 | grid[i][j] = new Cell(i*blockSize,j*blockSize,blockSize,blockSize,i+j); | |
21 | } | |
22 | } | |
23 | } | |
24 | ||
25 | void draw() { | |
26 | background(0); | |
27 | for (int i = 0; i < cols; i++) { | |
28 | for (int j = 0; j < rows; j++) { | |
29 | // display each object | |
30 | grid[i][j].display(); | |
31 | } | |
32 | } | |
33 | } | |
34 | ||
35 | // A Cell object | |
36 | class Cell { | |
37 | // A cell object knows about its location in the grid as well as its size with the variables x,y,w,h. | |
38 | float x,y; // x,y location | |
39 | float w,h; // width and height | |
40 | //float c; // color | |
41 | ||
42 | // Cell Constructor | |
43 | Cell(float tempX, float tempY, float tempW, float tempH, float tempColor) { | |
44 | x = tempX; | |
45 | y = tempY; | |
46 | w = tempW; | |
47 | h = tempH; | |
48 | ||
49 | } | |
50 | void display() { | |
51 | ||
52 | noStroke(); | |
53 | ||
54 | color[] palette=new color[5]; | |
55 | palette[0]=color(40,245,243); //cyan | |
56 | palette[1]=color(0,0,0); //black | |
57 | palette[2]=color(255,255,255); //white | |
58 | palette[3]=color(206,0,76); //hot pink | |
59 | palette[4]=color(118,242,100); //green | |
60 | ||
61 | ||
62 | fill(palette[int(random(1,3))]); | |
63 | ||
64 | ||
65 | ||
66 | rect(x,y,w,h); | |
67 | } | |
68 | } |