-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnoisy-circle.js
62 lines (50 loc) · 1.68 KB
/
noisy-circle.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const canvasSketch = require('canvas-sketch');
const createShader = require('canvas-sketch-util/shader');
const glsl = require('glslify');
// Setup our sketch
const settings = {
dimensions: [1024, 1024],
context: 'webgl',
animate: true,
duration: 5,
fps: 50
};
// Your glsl code
const frag = glsl(/* glsl */`
precision highp float;
uniform float playhead;
varying vec2 vUv;
#pragma glslify: noise = require(glsl-noise/simplex/3d);
float loopNoise (float x, float y, float t, float scale, float offset) {
float duration = scale;
float current = t * scale;
return ((duration - current) * noise(vec3(x, y, current + offset)) + current * noise(vec3(x, y, current - duration + offset))) / duration;
}
void main () {
float dist = length(vUv - vec2(0.5, 0.5));
float red = smoothstep(0.15, 0.155, loopNoise(vUv.x, vUv.y, playhead, 1., 0.));
float green = smoothstep(0.105, 0.108, loopNoise(vUv.x, vUv.y, playhead, 1., 120.));
float blue = .5;
// float blue = smoothstep(0.2, 0.205, noise(vec3(vUv.x, vUv.y, playhead*.5+100.)));
vec3 color = vec3(red, green, blue);
float alpha = smoothstep(0.250, 0.2482, dist);
gl_FragColor = vec4(color, alpha);
}
`);
// Your sketch, which simply returns the shader
const sketch = ({ gl }) => {
// Create the shader and return it
return createShader({
clearColor: "rgb(240, 248, 255)",
// Pass along WebGL context
gl,
// Specify fragment and/or vertex shader strings
frag,
// Specify additional uniforms to pass down to the shaders
uniforms: {
// Expose props from canvas-sketch
playhead: ({ playhead }) => playhead
}
});
};
canvasSketch(sketch, settings);