Published
Edited
Oct 15, 2021
2 stars
Insert cell
Insert cell
Insert cell
f = bqn`Noise ← {
𝕊p:
# Using Patricio Gonzalez Vivo's Algorithms
# from https://gist.github.com/patriciogonzalezvivo/670c22f3966e662d2f83
Smoothstep ← {
𝕊⟨e0, e1, x⟩:
t ← 0⌈1⌊(x-e0)÷(e1-e0)
t×t×(3.0 - 2.0×t)
}

Mix ← {
𝕊⟨x,y,a⟩:
x×(1-a)+y×a
}

Rand ← {
𝕊n:
1 | 43758.5453123 × •math.Sin +´⟨12.9898, 4.1414⟩×n
}

d ← ⟨0,1⟩
b ← ⌊p
f ← Smoothstep⟨0, 1, 1|p⟩
u ← Mix⟨Rand b, Rand (b + ⌽d), ⊑f⟩
v ← Mix⟨Rand (b + d), Rand (b + 1), ⊑f⟩
Mix⟨u,v, 1⊑f⟩
}`
Insert cell
cartesianGrid = bqn`(⊢≍⌜⊢)↕`
Insert cell
n = 50
Insert cell
noiseOutput = bqn`{𝕩¨𝕨}`(f, cartesianGrid(n))
Insert cell
{
const height = width;
const c = DOM.context2d(width, height);
const cell = width / n;
for (let i = 0; i < noiseOutput.length; i++) {
const d = noiseOutput[i] * 255;
c.fillStyle = `rgb(${d}, ${d}, ${d})`;
c.fillRect(cell * Math.floor(i / n), cell * (i % n), cell, cell);
}
return c.canvas;
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more