Published
Edited
Apr 18, 2020
1 fork
6 stars
WebGPU ShaderHydraulic Erosion SimulationHow Does Mapbox Raster Colorization Work?Arc Length of a Quadratic Bézier SplineMagnetic PendulumTracing Lamb Modes in the Complex PlaneMissing Fundamental IllusionSliced Optimal TransportLine Integral ConvolutionShanks TransformationUeda's AttractorCubic basis vs. Hermite interpolationBicubic Texture Interpolation using Linear FilteringFactor-of-Two Lanczos Image ResamplingAperiodic Monotileeqn [WIP]SDF Points with reglKnocking Down the Gates with our Friend JacobiFast Generalized Winding Numbers in 2DHTML+CSS Periodic Three-Body OrbitsClifford and de Jong AttractorsStrange Attractors on the GPU, Part 1: ImplementationStrange Attractors on the GPU, Part 2: Fun!Lawson's Klein BottleInteractive Multi-scale Turing PatternsComputing π with the Bailey-Borwein-Plouffe FormulaThe Double Pendulum MapMalkus WaterwheelRegister Allocation and the k-Coloring ProblemMultiscale Turing Patterns in WebGLSelecting the Right Opacity for 2D Point CloudsKuramoto-Sivashinsky Equation in 2DAdaptive Contouring in Fragment ShadersComplex function plotterGPU Voronoi Diagrams using the Jump Flooding AlgorithmBaker's MapHello, g9Dispersion in Water Surface WavesFake Transparency for 3D SurfacesUniformly Distributed Points on a SphereGPU BoidsGrouping Points with Principal Component AnalysisDomain Coloring for Complex FunctionsDrawing indexed mesh data as screen-space normals without duplicating dataFinding Roots in the Complex PlanePeriodic Planar Three-Body Orbits2D (Non-physical) N-body Gravity with Poisson's EquationHalf-Precision Floating-Point, VisualizedIntegers in Single-Precision Floating-PointDomain Coloring with Adaptive ContouringInstanced WebGL CirclesDouble Compound Pendulums3D Reaction-Diffusion
Mathematical Easter Egg Coloring
Toiletpaperfullerenes and Charmin Nanotubes
Also listed in…
WebGL
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
drawEgg = regl({
vert: `
precision highp float;
attribute vec3 aPosition, aNormal;
uniform mat4 projectionView;
uniform float time;
varying vec3 position, normal;
void main () {
position = aPosition;
normal = aNormal;
gl_Position = projectionView * vec4(position, 1);
}
`,
frag: `
precision highp float;
varying vec3 position, normal;
uniform vec3 eye; // Position of the camera, for use in lighting
uniform float time;

vec3 applyGamma (vec3 c, float gamma) {
return vec3(pow(c.r, gamma), pow(c.g, gamma), pow(c.b, gamma));
}

void main () {
// Define your coloring function here!
vec3 color = vec3(
0.5 +
0.3 * cos(position * 5.0) *
sin(position * 10.0 - 4.0 * time)
);

gl_FragColor = vec4(applyGamma(color, (1.0 / 2.2)), 1);
}
`,
attributes: {
aPosition: regl.prop('positions'),
aNormal: regl.prop('normals')
},
cull: { enable: true, face: 'back' },
elements: regl.prop('cells')
})
Insert cell
Insert cell
Insert cell
function egg(x, y, z) {
return y * y + Math.pow(1.2, y * 2) * 1.9 * (x * x + z * z) - 1;
}
Insert cell
domain = [[-1, 1], [-1, 1], [-1, 1]]
Insert cell
resolution = [100, 100, 100]
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
mesh = {
// Precompute the offset and slope so that converting grid coordinates to scalars is a bit faster.
const b = domain.map((b, i) => [b[0], (b[1] - b[0]) / (resolution[i] - 1)]);

// Use ndarray-proxy to create an ndarray that lazily returns the values of the function on a grid
const gridValues = ndarrayProxy(resolution, (i, j, k) =>
egg(b[0][0] + i * b[0][1], b[1][0] + j * b[1][1], b[2][0] + k * b[2][1])
);

const mesh = surfaceNets(gridValues);

// The positions in the mesh above are all in terms of grid coordinates.
// We scale them to our domain.
for (var i = 0; i < mesh.positions.length; i++) {
const p = mesh.positions[i];
p[0] = b[0][0] + b[0][1] * p[0];
p[1] = b[1][0] + b[1][1] * p[1];
p[2] = b[2][0] + b[2][1] * p[2];
}

mesh.normals = angleNormals(mesh.cells, mesh.positions);

return mesh;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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