xxxxxxxxxx
91
//var listOfColors = ["#1c77c3", "#39a9db", "#40bcd8", "#f39237", "#d63230", "#540d6e", "#ee4266", "#ffd23f", "#f3fcf0", "#1f271b"];
var listOfColors = ["#fcfcfc","#f7567c","#fba8b0","#fffae3","#99e1d9","#ff8811","#0075a2","#3f8efc","#1b4965"]
class Square{
constructor(px,py,s){
this.positionX = px
this.positionY = py
this.size = s
this.c = listOfColors[int(random(0, listOfColors.length))]
}
move(){
}
display(){
fill(this.c)
strokeWeight(4);
rect(this.positionX-this.size/2, this.positionY-this.size/2, this.size, this.size)
}
}
class SquareGrid{
constructor(){
this.squares = []
this.gridSize = 6
this.squareSize = 55
this.spacing = 65
this.positionX = width/2 - ((this.gridSize-1) * (this.spacing))/2
console.log(this.positionX)
this.positionY = height/2 - ((this.gridSize-1) * (this.spacing))/2
for(let i=0; i<this.gridSize; i++){
let row = []
for(let j=0; j<this.gridSize; j++){
row.push(
new Square((this.positionX + this.spacing * i),(this.positionY + this.spacing * j ),this.squareSize)
)
}
this.squares.push(row)
}
}
move(){
}
display(){
for(let i=0; i<this.gridSize; i++){
for(let j=0; j<this.gridSize; j++){
this.squares[i][j].display()
}
}
var selection1 = int(random(this.gridSize-1));
var selection2 = int(random(this.gridSize-1));
var col = listOfColors[int(random(0, listOfColors.length))]
this.squares[selection1][selection2].c = col
//this.squares[selection1+int(random(-1,1))][selection2+int(random(-1,1))].c = col
}
}
var fps = 60;
var capturer = new CCapture({
format: 'png',
framerate: fps
});
function setup() {
createCanvas(512, 512);
grid = new SquareGrid();
}
var startMillis;
function draw() {
background(220);
grid.display()
}