JavaScript preprocessors can help make authoring JavaScript easier and more convenient. For instance, CoffeeScript can help prevent easy-to-make mistakes and offer a cleaner syntax and Babel can bring ECMAScript 6 features to browsers that only support ECMAScript 5.

Any URL's added here will be added as `<script>`

s in order, and run *before* the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.

If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.

You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.

+ add another resource

If active, Pens will autosave every 30 seconds after being saved once.

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Visit your global Editor Settings.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

` ````
<canvas id="canv"></canvas>
```

` ````
body {
margin: 0;
}
canvas {
display: block;
width: 100vw;
height: 100vh;
}
```

` ````
import GLea from 'https://terabaud.github.io/hello-webgl/lib/glea/glea.mjs';
// this is just for code highlighting in VSCode
// via the glsl-literal extension
const glsl = x => x;
const frag = glsl`
precision highp float;
uniform float time;
uniform float width;
uniform float height;
const float PI = 3.141592654;
const float DEG = PI / 180.0;
vec2 coords() {
float vmin = min(width, height);
return vec2((gl_FragCoord.x - width * .5) / vmin,
(gl_FragCoord.y - height * .5) / vmin);
}
vec2 rotate(vec2 p, float a) {
return vec2(p.x * cos(a) - p.y * sin(a),
p.x * sin(a) + p.y * cos(a));
}
vec2 repeat(in vec2 p, in vec2 c) {
return mod(p, c) - 0.5 * c;
}
// Distance functions by Inigo Quilez
// https://iquilezles.org/www/articles/distfunctions2d/distfunctions2d.htm
float circle(in vec2 p, float radius) {
return length(p) - radius;
}
float pie( in vec2 p, in vec2 c, in float r )
{
p.x = abs(p.x);
float l = length(p) - r;
float m = length(p-c*clamp(dot(p,c),0.0,r)); // c = sin/cos of the aperture
return max(l,m*sign(c.y*p.x-c.x*p.y));
}
// function from https://www.shadertoy.com/view/3ll3zr
float sdHeart(in vec2 p, float s) {
p /= s;
vec2 q = p;
q.x *= 0.5 + .5 * q.y;
q.y -= abs(p.x) * .63;
return (length(q) - .7) * s;
}
float symmetricDiff(float a, float b)
{
// (A ∪ B) \ (A ∩ B)
return max(min(a, b), -max(a, b));
}
float subtract(float a, float b)
{
return max(-a, b);
}
vec3 shade(in vec2 p)
{
vec3 background = vec3(.2 + sin(time * .1) * .2, .1, .2);
vec3 foreground = vec3(.5 + .5 * sin(.015 + time * .1), .2 + p.y * .01, .9);
vec2 h = vec2(sin(90.0 * 3.14/180.0), cos(90.0 * 3.14/180.0));
float sdf0 = circle(p, 50.0);
sdf0 = subtract(circle(p, 40.0), sdf0);
float sdf = mix(sdf0, sdHeart(p + vec2(0, 2.0 +sin(time) * 4.0), 40.0), clamp(2.0 * sin(time * .1), 0.0, 1.0));
if (sdf > 0.0 && sdf < 1.0) {
// anti alias
return mix(background, foreground, sqrt(1.0 - sdf));
}
if (sdf < 0.0) {
return foreground;
}
float sdf2 = circle(p, 50.0);
vec3 col = sdf2 < 0.0 ? vec3(0) : background;
// Darken around surface
col = mix(col, col*1.0-exp(-2.0 * abs(min(sdf, sdf2))), 0.4);
// repeating lines
return col;
}
void main () {
float rota2 = 45. * DEG;
float zoom2 = .33;
vec2 p0 = repeat(rotate(coords() * zoom2, rota2), vec2(.125));
float zoom = 900.0;
float rota = mix(mod(time * .1, 2.0 * PI), 0.0, clamp(2.0 * sin(time * .1), 0.0, 1.0));
vec2 p1 = rotate(p0 * zoom, rota - rota2);
vec3 col = shade(p1);
gl_FragColor = vec4(col, 1.0);
}
`
const vert = glsl`
precision mediump float;
attribute vec2 position;
void main () {
gl_Position = vec4(position, 0, 1.0);
}
`
let texture = null;
const glea = new GLea({
shaders: [
GLea.fragmentShader(frag),
GLea.vertexShader(vert)
],
buffers: {
'position': GLea.buffer(2, [1, 1, -1, 1, 1,-1, -1,-1])
}
}).create();
function loop(time) {
const { gl } = glea;
glea.clear();
glea.uni('width', glea.width);
glea.uni('height', glea.height);
glea.uni('time', time * .005);
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
requestAnimationFrame(loop);
}
function setup() {
const { gl } = glea;
window.addEventListener('resize', () => {
glea.resize();
});
loop(0);
}
setup();
```

999px

Also see: Tab Triggers