xxxxxxxxxx
144
let r, buff, ws
let lines = []
let waves = []
let divs, scl;
const PHI = 1.618033
function setup() {
l = max(min(windowWidth, windowHeight), 790)
// l = 700
createCanvas(w = l, h = l)
bg = createGraphics(w, h)
r = random
divs = round(0.038 * l)
ws = w/5 //white space
// const rWidth = w/pal.length
bg.blendMode(ADD) // BLEND, ADD, DIFFERENCE, MULTIPLY, OVERLAY
for (let i = 0; i < l * 0.12345; i++) {
// const x = r(ws, w-ws)
// const y = r(ws, h-ws)
let theta = random(TAU)
let radius = random(w / 2)
const x = w / 2 + radius * cos(theta)
const y = h / 2 + radius * sin(theta)
let area = r(40, 160)
let amount = r(3, 6) * area
let weight = r(0.05, 0.15) * l
spotlight(bg, x, y, area, amount, weight)
}
// let len = l - 2 * ws
// let yStep = len / pal.length
// for (let i = 0; i < pal.length; i++) {
// const v1 = createVector(ws,ws + i * yStep)
// const v2 = createVector(ws + len, ws + i * yStep)
// // let ln = new lline(v1, v2, 120, color(pal[i]), color(pal[(i+1) % pal.length]), true)
// let ln = new lline(v1, v2, r([120, 40, 20]), color(pal[i]), color(pal[i]), true)
// ln.compute()
// lines.push(ln)
// }
// noLoop()
// Wave parameter object data structure
for (let i = 0; i < pal.length; i++) {
const waveObj = {
a1 : random(TAU),
b1 : random(TAU),
a2 : random(TAU),
b2 : random(TAU),
incr: [random(l / 157600, l / 19700), random(l / 157600, l / 19700), random(l / 157600, l / 19700), random(l / 157600, l / 19700)],
off: [0, 0, 0, 0]
}
waves.push(waveObj)
}
scl = 0.019 * l
}
function draw() {
background(41)
image(bg, 0, 0) // Draw the background
let len = l - 2 * ws
let yStep = len / pal.length
for (let i = 0; i < pal.length; i++) {
// stroke(pal[i])
// strokeWeight(floor(l * 0.061728))
// let ln = lines[i]
// ln.draw()
// line(ws,ws + i * yStep, ws + len, ws + i * yStep)
// Experiment
let w = waves[i]
drawWave({ x : ws, y: yStep / 2 + ws + i * yStep }, len, w.a1 + w.off[0], w.b1 + w.off[1], w.a2 + w.off[2], w.b2 + w.off[3], pal[i])
for (let k = 0; k < 4; k++)
w.off[k] += w.incr[k]
}
}
const pal = ["#FBF04C", "#4688CB", "#F76321", "#44B649",
"#ECB220", "#ED2526", "#A4DBE7"]
const pal2 = ["#EB8B32", "#99210A", "#F9E05C", "#4F97B2", "#1C1726"]
const pal3 = ["#47096f", "#0a1328", "#df952a", "#b8160d", "#570007", "#380371"]
function drawWave(v1, len, a1, b1, a2, b2, col) {
push()
let unit = len / divs
translate(v1.x, v1.y)
let x = unit / 2
stroke(col)
strokeWeight(10)
for (let i = 0; i < divs; i++) {
let y1 = f(x, a1, b1) * scl
let y2 = f(x, a2, b2) * scl
line(x, y1, x, y2)
x += unit
}
pop()
}
let f = (x, a, b) => {
return sin(2 * sin(PHI * x + b) + a)
}
function spotlight(buff, posX, posY, area, amount, weight) {
// stroke(random(pal))
let offset = weight / 4
buff.noStroke()
let col = random(pal3)
for (let i=0;i<amount;i++) {
buff.strokeWeight(weight)
const x = randomGaussian(posX, area)
const y = randomGaussian(posY, area)
const randomWeight = weight + r([-1, 1]) * r(offset)
const alpha = 1
buff.fill(red(col), green(col), blue(col), alpha)
buff.circle(x, y, randomWeight)
}
}
// Utility
function randi(low, high) {
return floor(random(low, high + 1))
}