Published
Edited
Aug 21, 2021
2 forks
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
N = params.N || 300
Insert cell
prngSeed = params.prngSeed || Date.now()
Insert cell
simplexSeed = params.simplexSeed || Date.now()
Insert cell
p = params.p || getRandomPalette()
Insert cell
palette = params.palette || shuffle(p)
Insert cell
Insert cell
Insert cell
await visibility(), bnb({
w, h,
w: w * 2, h: h * 2,
// webgl: true,
numFrames: 180,
fps: 20,
record: true,
// video: 'mp4',
// shaderPass: shaders.triGrid(),
shaderPass: [shaders.grey(), shaders.negative(), shaders.dither(8)],
shutterAngle: .1,
//samplesPerFrame: 4,
//chromaticAberration: .6,
preload: (s, g) => {
const prng = new PRNG(prngSeed)
class Rect {
constructor({x, y, w, h, n}) {
this.n = n
this.x = x
this.y = y
this.w = w
this.h = h
this.color = palette[prng.rand(1, palette.length-1)]
}
display(s, t) {
const scale = 10000
let sinT = s.sin(t * TAU) * .4
let cosT = s.cos(t * TAU) * .4
const n = simplex.noise4D((this.x + this.w / 2)/scale + sinT, (this.y + this.h / 2)/scale + cosT, -cosT*sinT, sinT*sinT)
s.noStroke()
s.fill(this.color)
s.push()
s.translate(this.x, this.y)
// s.drawingContext.beginPath()
s.drawingContext.rect(0, 0, this.w, this.h)
s.drawingContext.clip()
s.translate(this.w / 2, this.h / 2)
s.rotate(TAU * modularDist(n + 1, 2))
s.beginShape()
s.vertex(-this.w / 4, -this.h * 2)
s.vertex(this.w / 4, -this.h * 2)
s.vertex(this.w / 4, this.h * 2)
s.vertex(-this.w / 4, this.h * 2)
s.endShape(s.CLOSE)
s.pop()
}
}
const rects = []
array(3).forEach(i => divideRect4(0, 0, g.w, g.h, 4 + i, rects, 70, () => prng.rand(100)))
g.rects = rects.map(r => new Rect(r)).sort((a, b) => b.n - a.n)
},
draw: (s, t, g) => {
s.background(palette[0])
// s.drawingContext.globalCompositeOperation = 'soft-light'
s.drawingContext.globalAlpha = .8
g.rects.forEach(r => r.display(s, t))
}
})
Insert cell
shaders
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more