Published
Edited
May 15, 2018
3 forks
43 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
vertexShader = {
const shader = gl.createShader(gl.VERTEX_SHADER);
gl.shaderSource(shader, `
precision highp float;

const float PI = 3.14159265359;

const float a = -2.0;
const float b = -2.0;
const float c = -1.2;
const float d = 2.0;

attribute vec2 position;

void main() {
float x1, x2 = position.x;
float y1, y2 = position.y;
for (int i = 0; i < 8; i++) {
x1 = x2, y1 = y2;
x2 = sin(a * y1) - cos(b * x1);
y2 = sin(c * x1) - cos(d * y1);
}
gl_Position = vec4(x2 / 2.0, y2 / 2.0, 0.0, 1.0);
gl_PointSize = 1.0;
}
`);
gl.compileShader(shader);
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) throw gl.getShaderInfoLog(shader);
invalidation.then(() => gl.deleteShader(shader));
return shader;
}
Insert cell
Insert cell
u_a = gl.getUniformLocation(program, "a")
Insert cell
u_b = gl.getUniformLocation(program, "b")
Insert cell
u_c = gl.getUniformLocation(program, "c")
Insert cell
u_d = gl.getUniformLocation(program, "d")
Insert cell
Insert cell
a = -2 // + Math.sin(now / 8000)
Insert cell
b = -2
Insert cell
c = -1.2
Insert cell
d = 2
Insert cell
Insert cell
draw = {
setup;
// gl.uniform1f(u_a, a);
// gl.uniform1f(u_b, b);
// gl.uniform1f(u_c, c);
// gl.uniform1f(u_d, d);
gl.drawArrays(gl.POINTS, 0, n);
}
Insert cell
Insert cell
Insert cell
vertexBuffer = {
const array = new Float32Array(n * 2).map(() => Math.random() * 2 - 1);
const buffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
gl.bufferData(gl.ARRAY_BUFFER, array, gl.STATIC_DRAW);
invalidation.then(() => gl.deleteBuffer(buffer));
return buffer;
}
Insert cell
Insert cell
fragmentShader = {
const shader = gl.createShader(gl.FRAGMENT_SHADER);
gl.shaderSource(shader, `
precision highp float;

void main() {
gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
}
`);
gl.compileShader(shader);
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) throw gl.getShaderInfoLog(shader);
invalidation.then(() => gl.deleteShader(shader));
return shader;
}
Insert cell
Insert cell
program = {
const program = gl.createProgram();
gl.attachShader(program, vertexShader);
gl.attachShader(program, fragmentShader);
gl.linkProgram(program);
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) throw gl.getProgramInfoLog(program);
invalidation.then(() => gl.deleteProgram(program));
return program;
}
Insert cell
Insert cell
setup = {
const a_position = gl.getAttribLocation(program, "position");
gl.useProgram(program);
gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
gl.vertexAttribPointer(a_position, 2, gl.FLOAT, false, 0, 0);
gl.enableVertexAttribArray(a_position);
}
Insert cell
Insert cell
n = Math.pow(2, 18)
Insert cell
Insert cell
height = width
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