Published
Edited
Feb 28, 2021
Fork of Hexasphere
1 fork
1 star
Insert cell
Insert cell
gl.canvas
Insert cell
Insert cell
Insert cell
Insert cell
drawCountry = gl.regl({
vert: `
precision mediump float;

attribute vec3 position;
uniform mat4 model, view, projection;

void main () {
gl_Position = projection * view * model * vec4(position, 1);
}
`,
frag: `
precision mediump float;

void main () {
gl_FragColor = vec4(0, 0, 0, 1);
}
`,
attributes: {
position: gl.regl.prop("position")
},
uniforms: {
model: gl.regl.prop("model"),
},
primitive: 'line loop',
count: gl.regl.prop("count"),
})
Insert cell
setupCamera = gl.regl({
context: {
projection: (context) =>
mat4.perspective(
[],
Math.PI / 4,
context.viewportWidth / context.viewportHeight,
0.01,
1000.0,
),

view: (context, props) =>
mat4.lookAt(
[],
[3 * Math.cos(props.time), 3 * Math.sin(props.time), 0],
[0, 0, 0],
[0, 0, 1],
)
},

uniforms: {
view: gl.regl.context('view'),
projection: gl.regl.context('projection')
}
})
Insert cell
function draw(time) {
gl.regl.clear({
color: [1, 1, 1, 1],
depth: 1,
})
setupCamera({ time }, () => {
const model = mat4.identity([])

drawCountry(features.map(feature => ({
model,
position: feature.position,
count: feature.count
})))

// drawGraticule(graticule.map(points => ({
// view,
// position: points,
// count: points.length,
// })))
})
}
Insert cell
draw(now / 5000)
Insert cell
function polarToCartesian(lon0, lat0, R) {
const lat = lat0 * Math.PI / 180
const lon = lon0 * Math.PI / 180
const x = R * Math.cos(lat) * Math.cos(lon)
const y = R * Math.cos(lat) * Math.sin(lon)
const z = R * Math.sin(lat)

return [x, y, z];
}
Insert cell
Insert cell
drawGraticule = gl.regl({
vert: `
precision mediump float;

attribute vec3 position;
uniform mat4 model, view, projection;

void main () {
gl_Position = projection * view * model * vec4(position, 1);
}
`,
frag: `
precision mediump float;

void main () {
gl_FragColor = vec4(0, 0, 0, 0.1);
}
`,
attributes: {
position: gl.regl.prop("position")
},
uniforms: {
model: mat4.identity([]),
view: gl.regl.prop('view'),
projection: ({ viewportWidth, viewportHeight }) =>
mat4.perspective([],
Math.PI / 2,
viewportWidth / viewportHeight,
0.01,
1000),
},
primitive: 'line strip',
count: gl.regl.prop("count"),
})
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