Вход с водой
Форма входа над живой водой. Курсор роняет капли на ходу: медленная рука даёт мягкие круги, быстрая сильные.
- Вход и формы
- Бесплатно
- webgl
- Добавлен 9 октября 2026
<style>
/* page shell, only needed while this file is the whole page */
</style>
<!-- login start -->
<main class="cw">
<section class="cw-door">
<canvas class="cw-water" aria-hidden="true"></canvas>
<div class="cw-gate">
<h1 class="cw-gate-h cw-surface">Log in</h1>
<form class="cw-form" novalidate data-busy="Logging in" data-label="Logged in" data-done="Welcome back. Change this line or send people to their page.">
<label class="cw-hide" for="cw-user">Email</label>
<input class="cw-area" id="cw-user" name="email" type="email" autocomplete="username" placeholder="you@example.com" data-need="Enter your email.">
<label class="cw-hide" for="cw-pass">Password</label>
<input class="cw-area" id="cw-pass" name="password" type="password" autocomplete="current-password" placeholder="Password" data-need="Enter your password.">
<button class="cw-btn cw-btn-main" type="submit">Log in</button>
<p class="cw-note" role="status"></p>
</form>
</div>
</section>
</main>
<!-- login end -->
<script>
/* Clear Water Login by @codinvisual · t.me/CodinVisual · free for your own site, don't resell this file */
(() => {
const root = document.querySelector('.cw');
if (!root) return;
const WATER = { deep: [5, 30, 37], lift: [14, 70, 78], light: [127, 227, 214], sun: [246, 222, 178], words: [236, 228, 210] };
const RIPPLE_PUSH = .75, RIPPLE_SIZE = 32, RIPPLE_STEP = 80, RIPPLE_FADE = .992, BEND = .06, LIGHT = .09, WATER_PIXELS = 1.6e6;
const reduce = matchMedia('(prefers-reduced-motion: reduce)').matches;
root.classList.add('cw-js');
const $ = (s, el = root) => el.querySelector(s);
const $$ = (s, el = root) => [...el.querySelectorAll(s)];
const clamp = (x, a = 0, b = 1) => Math.min(b, Math.max(a, x));
const wait = ms => new Promise(r => setTimeout(r, ms));
/* water: a small wave simulation behind the form; it answers the pointer, a tap and the page scroll */
const pools = [];
$$('.cw-water').forEach(cv => {
if (reduce) return;
const host = cv.parentNode;
const gl = cv.getContext('webgl2', { alpha: false, antialias: false, depth: false });
if (!gl || !(gl.getExtension('EXT_color_buffer_float') || gl.getExtension('EXT_color_buffer_half_float'))) return;
const VERT = `#version 300 es
in vec2 a;
uniform vec2 px;
out vec2 uv, l, r, t, b;
void main() {
uv = a * .5 + .5;
l = uv - vec2(px.x, 0.); r = uv + vec2(px.x, 0.);
t = uv + vec2(0., px.y); b = uv - vec2(0., px.y);
gl_Position = vec4(a, 0., 1.);
}`;
const HEAD = '#version 300 es\nprecision highp float;\nprecision highp sampler2D;\nin vec2 uv, l, r, t, b;\nout vec4 o;\n';
const rgb = c => c.map(v => (v / 255).toFixed(3)).join(', ');
const SRC = {
// a drop: a smooth dent in the surface, the wave equation turns it into rings
drop: 'uniform sampler2D src; uniform vec2 at; uniform float ratio, size, amt;\nvoid main() {\n vec4 s = texture(src, uv); vec2 p = uv - at; p.x *= ratio;\n float k = max(0., 1. - length(p) / size);\n o = vec4(s.r + (.5 - .5 * cos(k * 3.14159)) * amt, s.g, 0., 1.);\n}',
// each cell is pulled toward the average of its neighbours; the edges throw the rings back
wave: 'uniform sampler2D src; uniform float fade;\nvoid main() {\n vec4 s = texture(src, uv);\n float avg = .25 * (texture(src, l).r + texture(src, r).r + texture(src, t).r + texture(src, b).r);\n float v = (s.g + (avg - s.r) * 1.4) * fade;\n // a little viscosity: short ripples die first, the wide rings travel on\n o = vec4((s.r + v + (avg - s.r) * .06) * .9996, v, 0., 1.);\n}',
show: `uniform sampler2D wave, words; uniform vec2 wpx, mid; uniform float now, rise, boost, ratio;
const vec3 DEEP = vec3(${rgb(WATER.deep)}), LIFT = vec3(${rgb(WATER.lift)}), LIGHT = vec3(${rgb(WATER.light)}), SUN = vec3(${rgb(WATER.sun)}), SAND = vec3(${rgb(WATER.words)});
float h(vec2 p) { return texture(wave, p).r; }
// light on the bottom, like sun through a calm pool: thin bright seams between soft cells, two layers drifting apart
float seams(vec2 p, float k) {
p += .35 * vec2(sin(p.y * 1.9 + now * .04 * k), sin(p.x * 1.6 - now * .03 * k));
p += .12 * vec2(sin(p.y * 4.3 - now * .05 * k), sin(p.x * 3.7 + now * .045 * k));
vec2 i = floor(p), f = fract(p);
float d1 = 9., d2 = 9.;
for (int y = -1; y <= 1; y++) for (int x = -1; x <= 1; x++) {
vec2 g = vec2(x, y), n = fract(sin(vec2(dot(i + g, vec2(127.1, 311.7)), dot(i + g, vec2(269.5, 183.3)))) * 43758.5453);
vec2 q = g + .5 + .4 * sin(now * .045 * k + 6.2832 * n) - f;
float d = dot(q, q);
if (d < d1) { d2 = d1; d1 = d; } else if (d < d2) d2 = d;
}
return 1. - smoothstep(0., .09, sqrt(d2) - sqrt(d1));
}
float cells(vec2 p) {
p *= vec2(ratio, 1.);
return seams(p * 4.4, 1.) * .65 + seams(p * 7.1 + 3.1, -.8) * .35;
}
void main() {
vec2 e1 = wpx * 2.;
float c0 = h(uv), hl = h(uv - vec2(e1.x, 0.)), hr = h(uv + vec2(e1.x, 0.)), hb = h(uv - vec2(0., e1.y)), ht = h(uv + vec2(0., e1.y));
vec2 slope = vec2(hr - hl, ht - hb);
float curve = hl + hr + hb + ht - 4. * c0;
vec2 q = uv - slope * ${BEND.toFixed(3)};
float e = 1. - pow(1. - rise, 3.);
vec2 tq = mid + (q - mid) / mix(.92, 1., e) - vec2(0., (1. - e) * .035);
float word = textureLod(words, tq, (1. - e) * 5.).a * e;
vec3 c = mix(DEEP, LIFT, smoothstep(0., 1.1, q.y * .75 + (1. - q.x) * .4));
c = mix(c, SAND, word * .92);
// where a crest bends the light together the bottom gets a thin bright line, behind it a soft shadow
float focus = -curve * 40., line = smoothstep(.25, 1.2, focus);
c += LIGHT * (cells(q) * (${LIGHT.toFixed(2)} + .5 * boost) * (1. - .45 * word) + line * .6) + SUN * smoothstep(1.1, 2.4, focus) * .3;
focus = clamp(focus, -.7, 0.);
c *= 1. + min(focus, 0.) * .4;
vec3 n = normalize(vec3(-slope * 5., 1.));
c += SUN * pow(max(dot(n, normalize(vec3(-.35, .45, 1.))), 0.), 500.) * 1.3;
o = vec4(c, 1.);
}`,
};
const shader = (type, src) => { const s = gl.createShader(type); gl.shaderSource(s, src); gl.compileShader(s); return s; };
const vs = shader(gl.VERTEX_SHADER, VERT);
const P = {};
for (const name in SRC) {
const p = gl.createProgram();
gl.attachShader(p, vs); gl.attachShader(p, shader(gl.FRAGMENT_SHADER, HEAD + SRC[name]));
gl.bindAttribLocation(p, 0, 'a'); gl.linkProgram(p);
if (!gl.getProgramParameter(p, gl.LINK_STATUS)) return;
const u = {};
for (let i = 0; i < gl.getProgramParameter(p, gl.ACTIVE_UNIFORMS); i++) { const n = gl.getActiveUniform(p, i).name; u[n] = gl.getUniformLocation(p, n); }
P[name] = { p, u };
}
gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer());
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1]), gl.STATIC_DRAW);
gl.enableVertexAttribArray(0); gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);
// the surface is a pair of textures that swap every step: height in red, speed in green
function target(w, h, id) {
const tex = gl.createTexture();
gl.activeTexture(gl.TEXTURE0 + id); gl.bindTexture(gl.TEXTURE_2D, tex);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RG16F, w, h, 0, gl.RG, gl.HALF_FLOAT, null);
const fbo = gl.createFramebuffer();
gl.bindFramebuffer(gl.FRAMEBUFFER, fbo); gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex, 0);
gl.viewport(0, 0, w, h); gl.clearColor(0, 0, 0, 1); gl.clear(gl.COLOR_BUFFER_BIT);
return { id, fbo, w, h, px: [1 / w, 1 / h] };
}
const words = gl.createTexture();
let sea, ratio = 1, mid = [.3, .6], tail = [.7, .6];
function build() {
const w = host.clientWidth, h = host.clientHeight;
if (!w || !h) return false;
ratio = w / h;
const k = Math.min(devicePixelRatio || 1, 2, Math.sqrt(WATER_PIXELS / (w * h)));
cv.width = Math.round(w * k); cv.height = Math.round(h * k);
// one cell of the surface is about 4 css pixels, so a ring looks the same in a tall first screen and a short band
const sh = Math.round(clamp(h / 4, 80, 210)), sw = Math.round(clamp(w / 4, 50, 480));
const a = target(sw, sh, 0), b = target(sw, sh, 1);
sea = { read: a, write: b, swap() { [sea.read, sea.write] = [sea.write, sea.read]; } };
paint(k);
return gl.checkFramebufferStatus(gl.FRAMEBUFFER) === gl.FRAMEBUFFER_COMPLETE;
}
// the bottom has no words here, the texture stays empty
function paint(k) {
const c = document.createElement('canvas');
c.width = cv.width; c.height = cv.height;
const x = c.getContext('2d');
gl.activeTexture(gl.TEXTURE2); gl.bindTexture(gl.TEXTURE_2D, words);
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, c);
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
gl.generateMipmap(gl.TEXTURE_2D);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
}
if (!build()) return;
root.classList.add('cw-wet');
function run(name, to, set) {
const { p, u } = P[name];
gl.useProgram(p);
if (u.px) gl.uniform2f(u.px, ...(to ? to.px : [1 / cv.width, 1 / cv.height]));
set(u);
gl.bindFramebuffer(gl.FRAMEBUFFER, to ? to.fbo : null);
gl.viewport(0, 0, to ? to.w : cv.width, to ? to.h : cv.height);
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
}
const drops = [];
function drop(x, y, size, amt) {
run('drop', sea.write, u => { gl.uniform1i(u.src, sea.read.id); gl.uniform2f(u.at, x, y); gl.uniform1f(u.ratio, ratio); gl.uniform1f(u.size, size); gl.uniform1f(u.amt, amt); });
sea.swap();
}
let shown = true, running = false, last = 0, acc = 0, start = 0, boost = 0, born = false;
function frame(now) {
if (!shown || document.hidden) { running = false; return; }
const t = now / 1000, dt = Math.min(t - last, .1); last = t;
const age = t - start;
// one drop falls by itself when the page opens, so people see this is water
if (!born && age > .55) { born = true; drops.push([tail[0], tail[1] + .02, RIPPLE_SIZE * 1.6 / host.clientHeight, -.9 * RIPPLE_PUSH]); }
while (drops.length) drop(...drops.shift());
acc = Math.min(acc + dt * 110, 6);
for (; acc >= 1; acc--) { run('wave', sea.write, u => { gl.uniform1i(u.src, sea.read.id); gl.uniform1f(u.fade, RIPPLE_FADE); }); sea.swap(); }
boost = Math.max(0, boost - dt / 1.4);
run('show', null, u => {
gl.uniform1i(u.wave, sea.read.id); gl.uniform1i(u.words, 2);
gl.uniform2f(u.wpx, ...sea.read.px); gl.uniform2f(u.mid, ...mid);
gl.uniform1f(u.now, t); gl.uniform1f(u.rise, clamp((age - .1) / 1.5)); gl.uniform1f(u.boost, boost); gl.uniform1f(u.ratio, ratio);
});
requestAnimationFrame(frame);
}
const wake = () => { if (running || !shown || document.hidden) return; running = true; requestAnimationFrame(t => { last = t / 1000; if (!start) start = last; frame(t); }); };
const spot = e => { const r = cv.getBoundingClientRect(); return [(e.clientX - r.left) / r.width, 1 - (e.clientY - r.top) / r.height]; };
// the pointer lets drops fall at an even step along its way: a slow hand sends soft rings, a fast one strong ones
let px = -1, py = -1, pt = 0, way = 0;
host.addEventListener('pointermove', e => {
const [x, y] = spot(e), now = performance.now() / 1000;
if (px >= 0) {
const H = host.clientHeight, far = Math.hypot((x - px) * ratio, y - py) * H, speed = far / Math.max(now - pt, 1 / 120) / 1000;
way += far;
if (way > RIPPLE_STEP) { way = 0; drops.push([x, y, RIPPLE_SIZE / H, -RIPPLE_PUSH * clamp(.25 + speed * .2, .25, .8)]); }
}
px = x; py = y; pt = now;
});
host.addEventListener('pointerleave', () => { px = -1; });
host.addEventListener('pointercancel', () => { px = -1; });
// a tap or a click on the water is a drop
host.addEventListener('pointerdown', e => {
if (e.target.closest('a, button, input, textarea, label')) return;
const [x, y] = spot(e);
drops.push([x, y, RIPPLE_SIZE * 1.4 / host.clientHeight, -RIPPLE_PUSH * .9]);
px = x; py = y; pt = performance.now() / 1000;
});
// scrolling the page rocks the water from its near edge
let top = scrollY;
addEventListener('scroll', () => {
const d = clamp((scrollY - top) / innerHeight, -.12, .12);
top = scrollY;
if (!shown || !d) return;
for (let i = 0; i < 4; i++) drops.push([(i + .5) / 4, .02, 110 / host.clientHeight, d * 2.2]);
}, { passive: true });
pools.push({
host,
splash(cx, cy) {
const r = cv.getBoundingClientRect(), x = (cx - r.left) / r.width, y = 1 - (cy - r.top) / r.height;
drops.push([x, y, RIPPLE_SIZE * 2.4 / host.clientHeight, -RIPPLE_PUSH * 1.6]);
boost = 1;
},
});
new ResizeObserver(() => { if (cv.width && Math.abs(host.clientWidth / host.clientHeight - ratio) > .01) build(); }).observe(host);
new IntersectionObserver(([e]) => { shown = e.isIntersecting; wake(); }).observe(cv);
document.addEventListener('visibilitychange', wake);
wake();
});
/* a form that went through sends one wide ring from its button; over the water it is a real wave and the bottom lights up */
function ring(x, y) {
if (reduce) return;
const pool = pools.find(p => { const r = p.host.getBoundingClientRect(); return x > r.left && x < r.right && y > r.top && y < r.bottom; });
if (pool) { pool.splash(x, y); return; }
const cv = document.createElement('canvas'), c = cv.getContext('2d'), k = Math.min(devicePixelRatio || 1, 2);
cv.className = 'cw-ring'; cv.width = innerWidth * k; cv.height = innerHeight * k;
root.append(cv);
const far = Math.hypot(Math.max(x, innerWidth - x), Math.max(y, innerHeight - y)), glow = getComputedStyle(root).getPropertyValue('--glow').trim();
const t0 = performance.now();
requestAnimationFrame(function grow(now) {
const age = (now - t0) / 1000;
c.setTransform(k, 0, 0, k, 0, 0); c.clearRect(0, 0, innerWidth, innerHeight);
for (const [lag, width] of [[0, 3], [.2, 1.5]]) {
const u = clamp((age - lag) / 1.5);
if (!u) continue;
c.beginPath(); c.arc(x, y, 20 + (1 - (1 - u) ** 3) * far, 0, Math.PI * 2);
c.lineWidth = width * (1 - .6 * u);
c.strokeStyle = `rgba(${glow}, ${(.8 * (1 - u)).toFixed(3)})`;
c.shadowColor = `rgba(${glow}, ${(.6 * (1 - u)).toFixed(3)})`; c.shadowBlur = 14;
c.stroke();
}
if (age < 1.75) requestAnimationFrame(grow); else cv.remove();
});
}
/* the form: checks the fields, waits for the server, then sends the wave */
$$('.cw-form').forEach(form => {
const btn = $('.cw-btn', form), note = $('.cw-note', form), fields = $$('.cw-input, .cw-area', form);
form.addEventListener('submit', async e => {
e.preventDefault();
const bad = fields.find(f => !f.value.trim() || f.type === 'email' && !/^\S+@\S+\.\S+$/.test(f.value.trim()));
fields.forEach(f => f.classList.toggle('cw-area-bad', f === bad));
form.classList.toggle('cw-form-bad', !!bad);
if (bad) {
note.textContent = bad.type === 'email' && bad.value.trim() ? 'That does not look like an email. Try one like name@example.com.' : bad.dataset.need || 'Fill in this field first.';
bad.focus();
return;
}
btn.disabled = true; btn.textContent = form.dataset.busy || 'Sending';
// a real server request goes here, for example:
// await fetch('/api/login', { method: 'POST', body: new FormData(form) });
await wait(700);
fields.forEach(f => { f.disabled = true; });
btn.textContent = form.dataset.label || 'Sent';
form.classList.add('cw-sent');
note.textContent = form.dataset.done || 'Thank you. We will write back soon.';
const r = btn.getBoundingClientRect();
ring(r.left + r.width / 2, r.top + r.height / 2);
});
fields.forEach(f => f.addEventListener('input', () => { form.classList.remove('cw-form-bad'); f.classList.remove('cw-area-bad'); note.textContent = ''; }));
});
})();
</script>
Проведите курсором по воде, кликните, чтобы уронить одну каплю. Введите любую почту и пароль и нажмите Log in: от кнопки пойдёт одна широкая волна.
Что можно поменять
Поменяйте число, сохраните файл и обновите страницу, разница будет видна сразу.
WATERcolorsЦвета воды, каждый как красный, зелёный, синий от 0 до 255.
RIPPLE_PUSH0.75Как сильно курсор волнует воду.
RIPPLE_SIZE32Ширина одной капли в пикселях.
RIPPLE_STEP80Расстояние между двумя каплями при движении курсора, в пикселях.
RIPPLE_FADE0.992Как долго живут круги, чем ближе к 1, тем дольше. Держите меньше 1.
LIGHT0.09Яркость света на дне, когда вода спокойна.
Как поставить на свой сайт
Страница входа студии, портфолио или продукта, везде, где первый экран может позволить себе немного движения.
Комментарии в коде на английском, так файл понятен любому разработчику.
CSS
Вставьте в свой файл стилей или в тег <style> внутри <head>.
/* page shell, only needed while this file is the whole page */HTML
Поставьте в то место страницы, где должен быть эффект.
<!-- login start --> <main class="cw"> <section class="cw-door"> <canvas class="cw-water" aria-hidden="true"></canvas> <div class="cw-gate"> <h1 class="cw-gate-h cw-surface">Log in</h1> <form class="cw-form" novalidate data-busy="Logging in" data-label="Logged in" data-done="Welcome back. Change this line or send people to their page."> <label class="cw-hide" for="cw-user">Email</label> <input class="cw-area" id="cw-user" name="email" type="email" autocomplete="username" placeholder="you@example.com" data-need="Enter your email."> <label class="cw-hide" for="cw-pass">Password</label> <input class="cw-area" id="cw-pass" name="password" type="password" autocomplete="current-password" placeholder="Password" data-need="Enter your password."> <button class="cw-btn cw-btn-main" type="submit">Log in</button> <p class="cw-note" role="status"></p> </form> </div> </section> </main> <!-- login end -->JavaScript
Вставьте перед закрывающим тегом </body>, внутри <script></script>.
/* Clear Water Login by @codinvisual · t.me/CodinVisual · free for your own site, don't resell this file */ (() => { const root = document.querySelector('.cw'); if (!root) return; const WATER = { deep: [5, 30, 37], lift: [14, 70, 78], light: [127, 227, 214], sun: [246, 222, 178], words: [236, 228, 210] }; const RIPPLE_PUSH = .75, RIPPLE_SIZE = 32, RIPPLE_STEP = 80, RIPPLE_FADE = .992, BEND = .06, LIGHT = .09, WATER_PIXELS = 1.6e6; const reduce = matchMedia('(prefers-reduced-motion: reduce)').matches; root.classList.add('cw-js'); const $ = (s, el = root) => el.querySelector(s); const $$ = (s, el = root) => [...el.querySelectorAll(s)]; const clamp = (x, a = 0, b = 1) => Math.min(b, Math.max(a, x)); const wait = ms => new Promise(r => setTimeout(r, ms)); /* water: a small wave simulation behind the form; it answers the pointer, a tap and the page scroll */ const pools = []; $$('.cw-water').forEach(cv => { if (reduce) return; const host = cv.parentNode; const gl = cv.getContext('webgl2', { alpha: false, antialias: false, depth: false }); if (!gl || !(gl.getExtension('EXT_color_buffer_float') || gl.getExtension('EXT_color_buffer_half_float'))) return; const VERT = `#version 300 es in vec2 a; uniform vec2 px; out vec2 uv, l, r, t, b; void main() { uv = a * .5 + .5; l = uv - vec2(px.x, 0.); r = uv + vec2(px.x, 0.); t = uv + vec2(0., px.y); b = uv - vec2(0., px.y); gl_Position = vec4(a, 0., 1.); }`; const HEAD = '#version 300 es\nprecision highp float;\nprecision highp sampler2D;\nin vec2 uv, l, r, t, b;\nout vec4 o;\n'; const rgb = c => c.map(v => (v / 255).toFixed(3)).join(', '); const SRC = { // a drop: a smooth dent in the surface, the wave equation turns it into rings drop: 'uniform sampler2D src; uniform vec2 at; uniform float ratio, size, amt;\nvoid main() {\n vec4 s = texture(src, uv); vec2 p = uv - at; p.x *= ratio;\n float k = max(0., 1. - length(p) / size);\n o = vec4(s.r + (.5 - .5 * cos(k * 3.14159)) * amt, s.g, 0., 1.);\n}', // each cell is pulled toward the average of its neighbours; the edges throw the rings back wave: 'uniform sampler2D src; uniform float fade;\nvoid main() {\n vec4 s = texture(src, uv);\n float avg = .25 * (texture(src, l).r + texture(src, r).r + texture(src, t).r + texture(src, b).r);\n float v = (s.g + (avg - s.r) * 1.4) * fade;\n // a little viscosity: short ripples die first, the wide rings travel on\n o = vec4((s.r + v + (avg - s.r) * .06) * .9996, v, 0., 1.);\n}', show: `uniform sampler2D wave, words; uniform vec2 wpx, mid; uniform float now, rise, boost, ratio; const vec3 DEEP = vec3(${rgb(WATER.deep)}), LIFT = vec3(${rgb(WATER.lift)}), LIGHT = vec3(${rgb(WATER.light)}), SUN = vec3(${rgb(WATER.sun)}), SAND = vec3(${rgb(WATER.words)}); float h(vec2 p) { return texture(wave, p).r; } // light on the bottom, like sun through a calm pool: thin bright seams between soft cells, two layers drifting apart float seams(vec2 p, float k) { p += .35 * vec2(sin(p.y * 1.9 + now * .04 * k), sin(p.x * 1.6 - now * .03 * k)); p += .12 * vec2(sin(p.y * 4.3 - now * .05 * k), sin(p.x * 3.7 + now * .045 * k)); vec2 i = floor(p), f = fract(p); float d1 = 9., d2 = 9.; for (int y = -1; y <= 1; y++) for (int x = -1; x <= 1; x++) { vec2 g = vec2(x, y), n = fract(sin(vec2(dot(i + g, vec2(127.1, 311.7)), dot(i + g, vec2(269.5, 183.3)))) * 43758.5453); vec2 q = g + .5 + .4 * sin(now * .045 * k + 6.2832 * n) - f; float d = dot(q, q); if (d < d1) { d2 = d1; d1 = d; } else if (d < d2) d2 = d; } return 1. - smoothstep(0., .09, sqrt(d2) - sqrt(d1)); } float cells(vec2 p) { p *= vec2(ratio, 1.); return seams(p * 4.4, 1.) * .65 + seams(p * 7.1 + 3.1, -.8) * .35; } void main() { vec2 e1 = wpx * 2.; float c0 = h(uv), hl = h(uv - vec2(e1.x, 0.)), hr = h(uv + vec2(e1.x, 0.)), hb = h(uv - vec2(0., e1.y)), ht = h(uv + vec2(0., e1.y)); vec2 slope = vec2(hr - hl, ht - hb); float curve = hl + hr + hb + ht - 4. * c0; vec2 q = uv - slope * ${BEND.toFixed(3)}; float e = 1. - pow(1. - rise, 3.); vec2 tq = mid + (q - mid) / mix(.92, 1., e) - vec2(0., (1. - e) * .035); float word = textureLod(words, tq, (1. - e) * 5.).a * e; vec3 c = mix(DEEP, LIFT, smoothstep(0., 1.1, q.y * .75 + (1. - q.x) * .4)); c = mix(c, SAND, word * .92); // where a crest bends the light together the bottom gets a thin bright line, behind it a soft shadow float focus = -curve * 40., line = smoothstep(.25, 1.2, focus); c += LIGHT * (cells(q) * (${LIGHT.toFixed(2)} + .5 * boost) * (1. - .45 * word) + line * .6) + SUN * smoothstep(1.1, 2.4, focus) * .3; focus = clamp(focus, -.7, 0.); c *= 1. + min(focus, 0.) * .4; vec3 n = normalize(vec3(-slope * 5., 1.)); c += SUN * pow(max(dot(n, normalize(vec3(-.35, .45, 1.))), 0.), 500.) * 1.3; o = vec4(c, 1.); }`, }; const shader = (type, src) => { const s = gl.createShader(type); gl.shaderSource(s, src); gl.compileShader(s); return s; }; const vs = shader(gl.VERTEX_SHADER, VERT); const P = {}; for (const name in SRC) { const p = gl.createProgram(); gl.attachShader(p, vs); gl.attachShader(p, shader(gl.FRAGMENT_SHADER, HEAD + SRC[name])); gl.bindAttribLocation(p, 0, 'a'); gl.linkProgram(p); if (!gl.getProgramParameter(p, gl.LINK_STATUS)) return; const u = {}; for (let i = 0; i < gl.getProgramParameter(p, gl.ACTIVE_UNIFORMS); i++) { const n = gl.getActiveUniform(p, i).name; u[n] = gl.getUniformLocation(p, n); } P[name] = { p, u }; } gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer()); gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1]), gl.STATIC_DRAW); gl.enableVertexAttribArray(0); gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0); // the surface is a pair of textures that swap every step: height in red, speed in green function target(w, h, id) { const tex = gl.createTexture(); gl.activeTexture(gl.TEXTURE0 + id); gl.bindTexture(gl.TEXTURE_2D, tex); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); gl.texImage2D(gl.TEXTURE_2D, 0, gl.RG16F, w, h, 0, gl.RG, gl.HALF_FLOAT, null); const fbo = gl.createFramebuffer(); gl.bindFramebuffer(gl.FRAMEBUFFER, fbo); gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex, 0); gl.viewport(0, 0, w, h); gl.clearColor(0, 0, 0, 1); gl.clear(gl.COLOR_BUFFER_BIT); return { id, fbo, w, h, px: [1 / w, 1 / h] }; } const words = gl.createTexture(); let sea, ratio = 1, mid = [.3, .6], tail = [.7, .6]; function build() { const w = host.clientWidth, h = host.clientHeight; if (!w || !h) return false; ratio = w / h; const k = Math.min(devicePixelRatio || 1, 2, Math.sqrt(WATER_PIXELS / (w * h))); cv.width = Math.round(w * k); cv.height = Math.round(h * k); // one cell of the surface is about 4 css pixels, so a ring looks the same in a tall first screen and a short band const sh = Math.round(clamp(h / 4, 80, 210)), sw = Math.round(clamp(w / 4, 50, 480)); const a = target(sw, sh, 0), b = target(sw, sh, 1); sea = { read: a, write: b, swap() { [sea.read, sea.write] = [sea.write, sea.read]; } }; paint(k); return gl.checkFramebufferStatus(gl.FRAMEBUFFER) === gl.FRAMEBUFFER_COMPLETE; } // the bottom has no words here, the texture stays empty function paint(k) { const c = document.createElement('canvas'); c.width = cv.width; c.height = cv.height; const x = c.getContext('2d'); gl.activeTexture(gl.TEXTURE2); gl.bindTexture(gl.TEXTURE_2D, words); gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true); gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, c); gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false); gl.generateMipmap(gl.TEXTURE_2D); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); } if (!build()) return; root.classList.add('cw-wet'); function run(name, to, set) { const { p, u } = P[name]; gl.useProgram(p); if (u.px) gl.uniform2f(u.px, ...(to ? to.px : [1 / cv.width, 1 / cv.height])); set(u); gl.bindFramebuffer(gl.FRAMEBUFFER, to ? to.fbo : null); gl.viewport(0, 0, to ? to.w : cv.width, to ? to.h : cv.height); gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4); } const drops = []; function drop(x, y, size, amt) { run('drop', sea.write, u => { gl.uniform1i(u.src, sea.read.id); gl.uniform2f(u.at, x, y); gl.uniform1f(u.ratio, ratio); gl.uniform1f(u.size, size); gl.uniform1f(u.amt, amt); }); sea.swap(); } let shown = true, running = false, last = 0, acc = 0, start = 0, boost = 0, born = false; function frame(now) { if (!shown || document.hidden) { running = false; return; } const t = now / 1000, dt = Math.min(t - last, .1); last = t; const age = t - start; // one drop falls by itself when the page opens, so people see this is water if (!born && age > .55) { born = true; drops.push([tail[0], tail[1] + .02, RIPPLE_SIZE * 1.6 / host.clientHeight, -.9 * RIPPLE_PUSH]); } while (drops.length) drop(...drops.shift()); acc = Math.min(acc + dt * 110, 6); for (; acc >= 1; acc--) { run('wave', sea.write, u => { gl.uniform1i(u.src, sea.read.id); gl.uniform1f(u.fade, RIPPLE_FADE); }); sea.swap(); } boost = Math.max(0, boost - dt / 1.4); run('show', null, u => { gl.uniform1i(u.wave, sea.read.id); gl.uniform1i(u.words, 2); gl.uniform2f(u.wpx, ...sea.read.px); gl.uniform2f(u.mid, ...mid); gl.uniform1f(u.now, t); gl.uniform1f(u.rise, clamp((age - .1) / 1.5)); gl.uniform1f(u.boost, boost); gl.uniform1f(u.ratio, ratio); }); requestAnimationFrame(frame); } const wake = () => { if (running || !shown || document.hidden) return; running = true; requestAnimationFrame(t => { last = t / 1000; if (!start) start = last; frame(t); }); }; const spot = e => { const r = cv.getBoundingClientRect(); return [(e.clientX - r.left) / r.width, 1 - (e.clientY - r.top) / r.height]; }; // the pointer lets drops fall at an even step along its way: a slow hand sends soft rings, a fast one strong ones let px = -1, py = -1, pt = 0, way = 0; host.addEventListener('pointermove', e => { const [x, y] = spot(e), now = performance.now() / 1000; if (px >= 0) { const H = host.clientHeight, far = Math.hypot((x - px) * ratio, y - py) * H, speed = far / Math.max(now - pt, 1 / 120) / 1000; way += far; if (way > RIPPLE_STEP) { way = 0; drops.push([x, y, RIPPLE_SIZE / H, -RIPPLE_PUSH * clamp(.25 + speed * .2, .25, .8)]); } } px = x; py = y; pt = now; }); host.addEventListener('pointerleave', () => { px = -1; }); host.addEventListener('pointercancel', () => { px = -1; }); // a tap or a click on the water is a drop host.addEventListener('pointerdown', e => { if (e.target.closest('a, button, input, textarea, label')) return; const [x, y] = spot(e); drops.push([x, y, RIPPLE_SIZE * 1.4 / host.clientHeight, -RIPPLE_PUSH * .9]); px = x; py = y; pt = performance.now() / 1000; }); // scrolling the page rocks the water from its near edge let top = scrollY; addEventListener('scroll', () => { const d = clamp((scrollY - top) / innerHeight, -.12, .12); top = scrollY; if (!shown || !d) return; for (let i = 0; i < 4; i++) drops.push([(i + .5) / 4, .02, 110 / host.clientHeight, d * 2.2]); }, { passive: true }); pools.push({ host, splash(cx, cy) { const r = cv.getBoundingClientRect(), x = (cx - r.left) / r.width, y = 1 - (cy - r.top) / r.height; drops.push([x, y, RIPPLE_SIZE * 2.4 / host.clientHeight, -RIPPLE_PUSH * 1.6]); boost = 1; }, }); new ResizeObserver(() => { if (cv.width && Math.abs(host.clientWidth / host.clientHeight - ratio) > .01) build(); }).observe(host); new IntersectionObserver(([e]) => { shown = e.isIntersecting; wake(); }).observe(cv); document.addEventListener('visibilitychange', wake); wake(); }); /* a form that went through sends one wide ring from its button; over the water it is a real wave and the bottom lights up */ function ring(x, y) { if (reduce) return; const pool = pools.find(p => { const r = p.host.getBoundingClientRect(); return x > r.left && x < r.right && y > r.top && y < r.bottom; }); if (pool) { pool.splash(x, y); return; } const cv = document.createElement('canvas'), c = cv.getContext('2d'), k = Math.min(devicePixelRatio || 1, 2); cv.className = 'cw-ring'; cv.width = innerWidth * k; cv.height = innerHeight * k; root.append(cv); const far = Math.hypot(Math.max(x, innerWidth - x), Math.max(y, innerHeight - y)), glow = getComputedStyle(root).getPropertyValue('--glow').trim(); const t0 = performance.now(); requestAnimationFrame(function grow(now) { const age = (now - t0) / 1000; c.setTransform(k, 0, 0, k, 0, 0); c.clearRect(0, 0, innerWidth, innerHeight); for (const [lag, width] of [[0, 3], [.2, 1.5]]) { const u = clamp((age - lag) / 1.5); if (!u) continue; c.beginPath(); c.arc(x, y, 20 + (1 - (1 - u) ** 3) * far, 0, Math.PI * 2); c.lineWidth = width * (1 - .6 * u); c.strokeStyle = `rgba(${glow}, ${(.8 * (1 - u)).toFixed(3)})`; c.shadowColor = `rgba(${glow}, ${(.6 * (1 - u)).toFixed(3)})`; c.shadowBlur = 14; c.stroke(); } if (age < 1.75) requestAnimationFrame(grow); else cv.remove(); }); } /* the form: checks the fields, waits for the server, then sends the wave */ $$('.cw-form').forEach(form => { const btn = $('.cw-btn', form), note = $('.cw-note', form), fields = $$('.cw-input, .cw-area', form); form.addEventListener('submit', async e => { e.preventDefault(); const bad = fields.find(f => !f.value.trim() || f.type === 'email' && !/^\S+@\S+\.\S+$/.test(f.value.trim())); fields.forEach(f => f.classList.toggle('cw-area-bad', f === bad)); form.classList.toggle('cw-form-bad', !!bad); if (bad) { note.textContent = bad.type === 'email' && bad.value.trim() ? 'That does not look like an email. Try one like name@example.com.' : bad.dataset.need || 'Fill in this field first.'; bad.focus(); return; } btn.disabled = true; btn.textContent = form.dataset.busy || 'Sending'; // a real server request goes here, for example: // await fetch('/api/login', { method: 'POST', body: new FormData(form) }); await wait(700); fields.forEach(f => { f.disabled = true; }); btn.textContent = form.dataset.label || 'Sent'; form.classList.add('cw-sent'); note.textContent = form.dataset.done || 'Thank you. We will write back soon.'; const r = btn.getBoundingClientRect(); ring(r.left + r.width / 2, r.top + r.height / 2); }); fields.forEach(f => f.addEventListener('input', () => { form.classList.remove('cw-form-bad'); f.classList.remove('cw-area-bad'); note.textContent = ''; })); }); })();
Подключение к серверу
Форма ничего не отправляет, пока вы её не подключили. Найдите a real server request goes here, поставьте туда свой fetch() и уберите таймер на следующей строке.
Полезно знать
- На телефоне касание это капля, а движение пальцем гонит круги следом.
- После входа дно бассейна на миг подсвечивается.
- Вода это один шейдер WebGL, картинок и библиотек нет.
Tilda, Webflow, WordPress
Нажмите «Скопировать весь код» вверху и вставьте его в один HTML-блок.
Добавить блок, Другое, T123 HTML-код. Вставьте и сохраните. Проверяйте на опубликованной странице, в редакторе скрипты не запускаются.
Панель Add, Embed. Вставьте и нажмите Save & Close. Свой код работает на опубликованном сайте.
Добавить блок, Произвольный HTML. Вставьте и нажмите «Обновить».



