Published
Edited
Jan 13, 2021
4 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
N = params.N || 15000
Insert cell
prngSeed = params.prngSeed || Date.now()
Insert cell
simplexSeed = params.simplexSeed || Date.now()
Insert cell
colorScale = params.colorScale || 'inferno'
Insert cell
Insert cell
Insert cell
bnb({
w, h,
webgl: true,
numFrames: 120,
fps: 20,
record: true,
// video: 'mp4',
chromaticAberration: 0.5,
samplesPerFrame: 8,

preload: (s, g) => {
const sphereRadius = 190
const scale = 180
const len = 30
class Pt {
constructor() {
const x = prng.rand(-100, 100)
const y = prng.rand(-100, 100)
const z = prng.rand(-100, 100)
this.pos = PVector(x, y, z).mag(sphereRadius)
this.noise = simplex.noise3D(...this.pos.clone().div(scale).toArray())
}

display(s, t) {
this.pos.rotateY(TAU / (g.numFrames * g.samplesPerFrame))
const sinT = s.sin((t * 4 + this.noise) * TAU)
const p = PVector.add(this.pos, this.pos.clone().mag(sinT * len))
const d = s.norm(p.dist(g.cameraPos), g.distMin, g.distMax)
s.strokeWeight(.1 + d * 2.1)
const c = scales[colorScale](sinT * .45 + .55)
s.stroke(...hexToRgb(c), d * 250)
s.point(...p.toArray())
}
}

g.pts = array(N).map(i => new Pt())
g.cameraPos = PVector(0, 0, 500)
g.distMin = g.cameraPos.dist(PVector(0, 0, sphereRadius + len))
g.distMax = g.cameraPos.dist(PVector(0, 0, -(sphereRadius + len)))
},

draw: (s, t, g) => {
s.background(scales[colorScale](0))
s.camera(...g.cameraPos.toArray(), 0, 0, 0, 0, 1, 0)
g.pts.forEach(pt => pt.display(s, t))
}
})
Insert cell
Insert cell
simplex = new SimplexNoise(simplexSeed)
Insert cell
Insert cell
import {array, shuffle, PRNG, SimplexNoise, PVector, TAU} from '@makio135/utilities'
Insert cell
import {getRandomPalette, displayPalettes, hexToRgb, scales, ramp} from '@makio135/give-me-colors'
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