Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let num, w;
- let cell = []; //Declare the array
- function setup() {
- createCanvas(400, 400);
- num = 3;
- for(let i = 0; i < num; i++){
- let arr = [];
- for(let j = 0; j < num; j++){
- arr.push(new Cell(i,j));
- }
- cell.push(arr);
- }
- w = width/num;
- }
- function draw() {
- background(220);
- for(let i = 0; i < num; i++){
- for(let j = 0; j < num; j++){
- cell[i][j].show();
- }
- }
- }
- class Cell{
- constructor(x,y){
- this.x = x;
- this.y = y;
- this.count = 0;
- if(random(2)>1){
- this.isAlive = true;
- } else {
- this.isAlive = false;
- }
- }
- show(){
- if(this.isAlive){
- fill(255);
- } else {
- fill(0);
- }
- rect(this.x*w, this.y*w, w, w);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment