xxxxxxxxxx
73
const WIDTH = 800
const HEIGHT = 800
const ROWS = 50
const COLS = 50
const CELL = WIDTH / COLS
function setup() {
createCanvas(WIDTH, HEIGHT)
noLoop()
}
function draw() {
background(220)
for (let _ of lines()) {
const [x0, y0, x1, y1] = _
line(x0, y0, x1, y1)
}
}
function *lines() {
for (let line of horizontalLines()) {
yield line
}
for (let line of verticalLines()) {
yield line
}
}
function *horizontalLines() {
for (let i = 1; i < ROWS; i++) {
let xON = random(1) > 0.5
for (let j = 0; j < COLS; j++) {
let x0 = j * CELL
let y0 = i * CELL
let x1 = x0 + CELL
let y1 = y0 + CELL
if (xON) {
if (j % 2 == 0) {
yield [x0, y0, x1, y0]
}
} else {
if (j % 2 == 1) {
yield [x0, y0, x1, y0]
}
}
}
}
}
function *verticalLines() {
for (let j = 1; j < COLS; j++) {
let yON = random(1) > 0.5
for (let i = 0; i < ROWS; i++) {
let x0 = j * CELL
let y0 = i * CELL
let x1 = x0 + CELL
let y1 = y0 + CELL
if (yON) {
if (i % 2 == 0) {
yield [x0, y0, x0, y1]
}
} else {
if (i % 2 == 1) {
yield [x0, y0, x0, y1]
}
}
}
}
}