xxxxxxxxxx
64
function setup() {
createCanvas(600, 600);
noLoop()
colorMode(HSB, 1, 1, 1)
noStroke()
num_rows = 50
num_tiles = num_rows * num_rows
tile_height = height / num_rows
tiles = []
}
function draw() {
background(220);
for (let j = 0; j < num_rows; j++) {
for (let i = 0; i < num_rows; i++) {
tile = new RandomTile(tile_height)
tile.draw()
tiles.push(tile)
// tile_x = i / num_rows * width
// tile_y = j / num_rows * height
// tile_number = i + j * num_rows
// tile_hue = map(tile_number, 0, num_tiles, 0, 1)
// tiles.push({
// x: tile_x,
// y: tile_y,
// hue: tile_hue
// })
// fill(tile_hue, 1.0, 1.0)
// rect(tile_x, tile_y, tile_height, tile_height)
}
}
}
class Tile {
constructor(x, y, tile_height, tile_color) {
this.x = x
this.y = y
this.height = tile_height
this.color = tile_color
}
draw() {
fill(this.color)
rect(this.x, this.y, this.height, this.height)
}
}
class RandomTile extends Tile {
constructor(tile_height) {
super(tile_height)
this.x = random(width)
this.y = random(height)
this.setColor()
}
setColor() {
push()
colorMode(HSB, 1, 1, 1)
this.color = color(this.hue, 1, 1)
pop()
}
draw() {
fill(this.color)
rect(this.x, this.y, this.height, this.height)
}
}