Skip to content

A toolbox of film styles made in code for Claude Code: 66 ready to use, and your own. Each style is a style prompt plus a demo film made entirely in code by Claude Opus 5.5, with no video model. By Lemomo. · 一套用代码做片的风格工具箱:66 种现成风格,也能做出你自己的

5.3 KB
Raw Blame
// Low-poly sea: triangle-mesh vertex animation (several sets of sines), flatShading makes each triangle reflect on its own;
// shallows colour is driven by a shallow-water map drawn live from "the tiles that have grown so far" (the lagoon grows with the island)
import * as THREE from 'three';

// CPU version of the same wave function (the buoy and boat bob with it)
export function waveH(x, z, t, amp = 1) {
  return amp * (.075 * Math.sin(.9 * x + 1.25 * t) + .06 * Math.sin(.77 * z - 1.05 * t + 1.3)
    + .045 * Math.sin(1.6 * (x + z) + 2.0 * t) + .03 * Math.sin(2.3 * x - 1.9 * z + 2.6 * t));
}
const WAVE_GLSL = `
  float waveH(vec2 p, float t, float amp){
    return amp * (.075 * sin(.9 * p.x + 1.25 * t) + .06 * sin(.77 * p.y - 1.05 * t + 1.3)
      + .045 * sin(1.6 * (p.x + p.y) + 2.0 * t) + .03 * sin(2.3 * p.x - 1.9 * p.y + 2.6 * t));
  }`;

export const SHALLOW_SPAN = 64;   // world extent covered by the shallow-water map (centred on the origin)

export function makeSea(scene) {
  const cv = document.createElement('canvas'); cv.width = cv.height = 512;
  const sg = cv.getContext('2d');
  const shallowTex = new THREE.CanvasTexture(cv); shallowTex.colorSpace = THREE.NoColorSpace; shallowTex.flipY = false;
  const U = {
    uTime: { value: 0 }, uAmp: { value: 1 }, uDeep: { value: new THREE.Color('#3aa3b8') }, uShal: { value: new THREE.Color('#86e0d2') },
    uShallow: { value: shallowTex }, uSpan: { value: SHALLOW_SPAN }, uFoam: { value: new THREE.Color('#ffffff') },
    uFwd: { value: new THREE.Vector2(0, -1) }, uTgt: { value: new THREE.Vector2() }, uSpanF: { value: 20 }, uNight: { value: 0 },
    uBeam: { value: new THREE.Vector4(0, 0, .1, 60) }, uBeamCol: { value: new THREE.Color('#ffe9b8') },
  };
  const mkMat = (near) => {
    const m = new THREE.MeshStandardMaterial({ color: '#ffffff', flatShading: true, roughness: .55, metalness: 0 });
    m.onBeforeCompile = sh => {
      Object.assign(sh.uniforms, U);
      sh.vertexShader = sh.vertexShader
        .replace('#include <common>', `#include <common>\nuniform float uTime, uAmp; varying vec2 vW;${WAVE_GLSL}`)
        .replace('#include <begin_vertex>', `#include <begin_vertex>
          vec4 wp0 = modelMatrix * vec4(transformed, 1.);
          vW = wp0.xz;
          transformed.z += waveH(wp0.xz, uTime, uAmp);`);   // the plane was first rotated -90° around x, so local z = world y
      sh.fragmentShader = sh.fragmentShader
        .replace('#include <common>', `#include <common>\nuniform vec3 uDeep, uShal, uFoam, uBeamCol; uniform sampler2D uShallow; uniform float uSpan, uSpanF, uNight, uTime; uniform vec2 uFwd, uTgt; uniform vec4 uBeam; varying vec2 vW;\nfloat hh(vec2 p){ p = fract(p * vec2(233.34, 851.73)); p += dot(p, p + 23.45); return fract(p.x * p.y); }`)
        .replace('#include <color_fragment>', `#include <color_fragment>
          vec2 suv = vW / uSpan + .5;
          float s = ${near ? 'texture2D(uShallow, suv).r' : '0.'};
          if (suv.x < 0. || suv.y < 0. || suv.x > 1. || suv.y > 1.) s = 0.;
          vec3 wc = mix(uDeep, uShal, smoothstep(.05, .85, s));
          wc = mix(wc, uFoam, smoothstep(.9, .99, s) * .55);
          // night: darker near, brightening toward the sky band in the distance
          float farK = dot(vW - uTgt, uFwd) / uSpanF;
          wc *= mix(1., mix(.55, 1.12, smoothstep(-.55, .9, farK)), uNight);
          diffuseColor.rgb = wc;`)
        .replace('#include <emissivemap_fragment>', `#include <emissivemap_fragment>
          // water lit by the lighthouse beam: a bright band + glinting highlights on the waves
          if (uBeam.y > 0.) {
            vec2 rel = vW; float r = length(rel);
            float da = abs(mod(atan(rel.y, rel.x) - uBeam.x + 3.14159265, 6.2831853) - 3.14159265);
            float hw = uBeam.z * (1. + 1.8 / max(r, .5));
            float band = smoothstep(hw, hw * .25, da) * smoothstep(1.5, 4., r) * pow(clamp(1. - r / uBeam.w, 0., 1.), 1.2);
            vec2 cell = floor(vW * 2.2); float tw = hh(cell + floor(uTime * 7.) * .137);
            float glint = pow(tw, 14.) * 3.5;
            totalEmissiveRadiance += uBeamCol * band * uBeam.y * (.55 + glint);
          }`);
    };
    return m;
  };
  const geo = new THREE.PlaneGeometry(220, 220, 200, 200).toNonIndexed();
  const near = new THREE.Mesh(geo, mkMat(true)); near.rotation.x = -Math.PI / 2; near.receiveShadow = false; scene.add(near);
  const far = new THREE.Mesh(new THREE.PlaneGeometry(5000, 5000, 180, 180), mkMat(false)); far.rotation.x = -Math.PI / 2; far.position.y = -.55; scene.add(far);

  // shallow-water map: each frame, draw blurred round spots from tile positions and rise progress
  function drawShallow(blobs) {
    sg.fillStyle = '#000'; sg.fillRect(0, 0, 512, 512);
    const k = 512 / SHALLOW_SPAN;
    for (const [x, z, r, a] of blobs) {
      if (a <= 0) continue;
      const px = (x / SHALLOW_SPAN + .5) * 512, py = (z / SHALLOW_SPAN + .5) * 512, rr = r * k;
      const gr = sg.createRadialGradient(px, py, 0, px, py, rr);
      gr.addColorStop(0, `rgba(255,255,255,${a})`); gr.addColorStop(.55, `rgba(255,255,255,${a * .8})`); gr.addColorStop(1, 'rgba(255,255,255,0)');
      sg.globalCompositeOperation = 'lighten'; sg.fillStyle = gr; sg.beginPath(); sg.arc(px, py, rr, 0, 7); sg.fill();
    }
    sg.globalCompositeOperation = 'source-over';
    shallowTex.needsUpdate = true;
  }
  return { near, far, U, drawShallow };
}