Published
Edited
May 3, 2022
1 fork
Insert cell
Insert cell
Insert cell
Insert cell
createRegl = require("regl")
Insert cell
Insert cell
canvas = html`<canvas width=300 height=200>`
Insert cell
Insert cell
regl = createRegl(canvas)
Insert cell
Insert cell
drawTriangle = regl({
// In a draw call, we can pass the shaders source code to regl
frag: `
precision mediump float;
uniform vec4 color;
void main () {
gl_FragColor = color;
}`,

vert: `
attribute vec2 position;
void main () {
gl_Position = vec4(position, 0, 1);
}`,

// These are the vertex attributes that will be passed
// on to the vertex shader
attributes: {
position: [
[-1, 0],
[0, -1],
[1, 1]
]
},

// These are the uniforms, i.e., global shader variables that are set
// from inside the host (CPU) program
uniforms: {
color: [1, 0, 0, 1]
},

// Total number of vertices to be fed into the pipeline
count: 3
})
Insert cell
Insert cell
draw = {
// First clear the frame buffer
regl.clear({
color: [0, 0, 0, 1]
})
// And then draw the triangle
drawTriangle()
}
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