Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //create a random two color block, define block sizes, number of rows, numbers of columns, define colors
- //by fbz
- Cell[][] grid;
- int numPixels;
- int blockSize = 4;
- int cols = 10;
- int rows = 4;
- void setup() {
- noLoop();
- size(cols*blockSize,rows*blockSize);
- grid = new Cell[cols][rows];
- for (int i = 0; i < cols; i++) {
- for (int j = 0; j < rows; j++) {
- grid[i][j] = new Cell(i*blockSize,j*blockSize,blockSize,blockSize,i+j);
- }
- }
- }
- void draw() {
- background(0);
- for (int i = 0; i < cols; i++) {
- for (int j = 0; j < rows; j++) {
- // display each object
- grid[i][j].display();
- }
- }
- }
- // A Cell object
- class Cell {
- // A cell object knows about its location in the grid as well as its size with the variables x,y,w,h.
- float x,y; // x,y location
- float w,h; // width and height
- //float c; // color
- // Cell Constructor
- Cell(float tempX, float tempY, float tempW, float tempH, float tempColor) {
- x = tempX;
- y = tempY;
- w = tempW;
- h = tempH;
- }
- void display() {
- noStroke();
- color[] palette=new color[5];
- palette[0]=color(40,245,243); //cyan
- palette[1]=color(0,0,0); //black
- palette[2]=color(255,255,255); //white
- palette[3]=color(206,0,76); //hot pink
- palette[4]=color(118,242,100); //green
- fill(palette[int(random(1,3))]);
- rect(x,y,w,h);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement