xxxxxxxxxx
77
function deform(poly, n, variance) {
if(n == 0) return poly
let res = []
for(let i = 0; i < poly.length - 1; i++) {
let curr = poly[i].slice()
let next = poly[i + 1].slice()
let len = Math.sqrt(Math.pow(curr[0] - next[0], 2),
Math.pow(curr[1] - next[1], 2))
let mid = [(curr[0] + next[0]) / 2, (curr[1] + next[1]) / 2];
mid[0] = randomGaussian(mid[0], variance * len)
mid[1] = randomGaussian(mid[1], variance * len)
let inner = deform([curr, mid, next], n - 1,
variance)
res = res.concat(inner)
}
return res
}
function poly(radius, n) {
let res = []
radius = radius || 323.0
n = n || 6
let angle = (Math.PI * 2) / n
for(let i = 0; i < n; i++) {
res.push([Math.sin(i * angle) * radius,
Math.cos(i * angle) * radius])
}
return res
}
function drawPoly(poly) {
beginShape()
for(let pt of poly) vertex(pt[0], pt[1])
endShape(CLOSE)
}
function setup() {
noLoop()
createCanvas(windowWidth, windowHeight)
noStroke()
}
function rep(fn, d, n) {
let res = d
for(let i = 0; i < n; i++) res = fn(res)
return res
}
function draw() {
push()
translate(width / 2, height / 2)
background(250,225,195)
let std = 20
let redLayers = new Array(5).fill()
.map((x, i) => deform(poly(100, noise(i) * 10), 5, 0.2))
let yellowLayers = new Array(50).fill()
.map((x, i) => deform(poly(100, noise(i) * 10), 4, 0.3))
for(let i = 0; i < redLayers.length + yellowLayers.length; i++) {
if(Math.floor(i / 5) % 2 == 0) {
fill(209, 49, 89, 10)
push()
translate(randomGaussian(0, std), randomGaussian(0, std))
drawPoly(redLayers[i % redLayers.length])
pop()
} else if (Math.floor(i / 5) % 2 == 1) {
fill(238, 255, 0, 20)
push()
translate(randomGaussian(0, std), 100 + randomGaussian(0, std))
drawPoly(yellowLayers[i % yellowLayers.length])
pop()
}
}
}