xxxxxxxxxx
39
// Width of a strip of cloth.
var stripWidth = 40
// Possible color values for strips.
var stripColors = ["#e1c943", "#dd4830", "#9e949f", "#080c12"]
// Chance that we will weave under a particular strip.
var chance = 0.75
function setup() {
createCanvas(400, 400)
noLoop()
}
function draw() {
background("#f0f2ed")
for (var x = 0; x < width; x += 2 * stripWidth) {
fill(random(stripColors))
noStroke()
rect(x, 0, stripWidth, height)
}
for (var y = 0; y < height; y += 2 * stripWidth / 3) {
var h = 2 * stripWidth / 3
fill(random(stripColors))
noStroke()
for (x = 0; x < width; x += 2 * stripWidth) {
if (random() < chance) {
// Go over
rect(x, y, 2 * stripWidth, h / 2)
} else {
// Go under
rect(x + stripWidth, y, stripWidth, h / 2)
}
}
}
}