Disclaimer
First of – don’t even think about trying to understand everything which is going in there. As a beginner you should really work your way up and at some point inventing your own fancy projects.
Implementation
HTML
<head>
<!-- Other stuff -->
<script defer src="https://raw.githack.com/strangerintheq/ShaderToy/master/ShaderToy.js"></script>
<script defer src="shader.js"></script>
<!-- Other scripts of yours -->
</head>
You are basically adding two scripts. The first one from a website the second one to one you have to copy yourself (that is the one you could see in the Codepen JS section).
JS
// filename: "shader.js"
// https://thelig.ht/chladni/
let uf = {xy: '2f'};
addEventListener('mousemove', e => uf.xy([e.x/innerWidth,e.y/innerHeight]))
new ShaderToy(`void main(void) {
const float PI = 3.14159265;
vec2 p = (2.0 * gl_FragCoord.xy - resolution.xy) / resolution.y;
vec4 s1 = vec4(1.0, 1.0, 1.0, 2.0);
vec4 s2 = vec4(-4.0, 4.0, 4.0, 4.6);
float tx = sin(time)*0.1;
float ty = cos(time)*0.1;
float a = mix(s1.x, s2.x, xy.x+tx);
float b = mix(s1.y, s2.y, xy.x+tx);
float n = mix(s1.z, s2.z, xy.y+ty);
float m = mix(s1.w, s2.w, xy.y+ty);
float max_amp = abs(a) + abs(b);
float amp = a * sin(PI*n*p.x) * sin(PI*m*p.y) + b * sin(PI*m*p.x) * sin(PI*n*p.y);
float col = 1.0 - smoothstep(abs(amp), 0.0, 0.1);
gl_FragColor = vec4(vec3(col), 1.0);
}`, {uniforms:uf}).fullscreen().loop();
I didn’t bother to check what is going on there. If you are interested maybe you like to look up some tutorials about shaders.
CSS
canvas {
z-index: -1;
position: fixed;
top: 0;
}
Add this either in an external stylesheet or in your head section.
The Script works by creating a canvas on your page. This CSS moves it behind every element on your page (z-index: -1
), makes it immovable (position: fixed
) and starting at the very top edge of your window (top: 0
).