Skip to content

Instantly share code, notes, and snippets.

@vlandham
Last active September 25, 2017 01:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vlandham/0223315b7a1896e5a22c89f283d1b0fc to your computer and use it in GitHub Desktop.
Save vlandham/0223315b7a1896e5a22c89f283d1b0fc to your computer and use it in GitHub Desktop.
regl dots basic
<!DOCTYPE html>
<title>Simple regl Dots Example</title>
<body>
<script src="https://npmcdn.com/regl@1.3.0/dist/regl.js"></script>
<script src="index.js"></script>
</body>
// In practice, you would probably import/require regl
// const regl = require('regl')();
// In this block, it is already loaded, so we just
// initialize it. For more info, see:
// https://github.com/regl-project/regl#standalone-script-tag
var regl = createREGL();
var drawDots = regl({
frag: `
precision mediump float;
uniform vec4 color;
void main () {
gl_FragColor = color;
}`,
vert: `
precision mediump float;
attribute vec2 position;
// @change acquire the pointWidth uniform
// this is set by the uniforms section below
uniform float pointWidth;
void main () {
// @change Set gl_PointSize global to
// configure point size
gl_PointSize = pointWidth;
gl_Position = vec4(position, 0, 1);
}`,
attributes: {
position: function(context, props) {
// @change I tweaked the constants here so
// the dots are not off the screen
return [
[-1 * Math.cos(context.tick / 100), 0.2],
[Math.sin(context.tick / 100), -0.8],
[Math.sin(context.tick / 100), 0.8]
];
}
},
uniforms: {
color: function(context, props) {
return props.color;
},
// @change: Add a pointWidth uniform -
// set by a prop
pointWidth: regl.prop('pointWidth')
},
count: 3,
// @change: Set our primitive to points
primitive: 'points'
})
regl.frame(function(context) {
drawDots({
color: [0.208, 0.304, 1.000, 1.000],
// @change: Pass in the pointWidth prop
pointWidth: 10.0
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment