Logo Code Loop

Code Loop

Cộng đồng
dotslashsimran
code-loop

Make a seamless, perfectly looping generative video in code, from a three.js scene or a raw GLSL fragment shader, rendered frame-perfect with jittered anti-aliasing and motion blur, then checked for a visible seam, freezing and blinking. Use when asked for a "seamless loop", a "perfect loop", "generative art video", a "shader loop", "three.js animation to video", to "render a looping animation", a looping GIF from code, or any code-driven animation that has to loop without a visible cut.

Tổng quan

Nhà phát hànhdotslashsimran
Kho mãsimcraft
Tên kỹ năngcode-loop
Sao
362
Bản fork
25
Tệp đi kèm
5
Giấy phépMIT
Liên kết
  • Hướng dẫn bằng Markdown

    Tệp SKILL.md được mô hình tải khi cần, nên chỉ tốn token khi có yêu cầu thực sự phù hợp.

  • Dùng được với mọi LLM

    Kỹ năng AI là Markdown thuần túy, không phải mã dành riêng cho một nhà cung cấp, nên dùng được với GPT, Claude, Gemini, Grok hoặc mô hình cục bộ.

  • 5 tệp đi kèm

    Các tập lệnh, mẫu và tài liệu tham khảo mà mô hình có thể đọc khi làm việc. Các tệp chỉ cho phép đọc và không bao giờ được thực thi.

  • Mã nguồn mở

    Được dotslashsimran công bố trên GitHub. Hãy đọc nội dung nguồn trước khi cài đặt.

Cài đặt

Cài đặt kỹ năng AI Code Loop trong TypingMind để dùng với bất kỳ LLM nào, hoặc thêm vào một tác nhân AI khác có thể đọc SKILL.md.

1

Cài đặt trong TypingMind

TypingMind cài đặt kỹ năng trực tiếp từ thư mục GitHub — đọc SKILL.md, đóng gói các tệp tài nguyên và lưu kết quả trên máy.

  1. Mở ứng dụng và vào Plugin → Kỹ năng.
  2. Chọn "Cài đặt từ GitHub".
  3. Dán URL thư mục kỹ năng bên dưới và xác nhận.
    https://github.com/dotslashsimran/simcraft/tree/main/skills/video/code-loop
  4. Bật kỹ năng trong từng cuộc trò chuyện mà bạn muốn sử dụng kỹ năng đó.
Plugin → Kỹ năng → Thêm kỹ năng → Từ URL GitHub, sau đó dán URL thư mục và nhấn Tiếp tục.
2

Cài đặt trong tác nhân AI khác

Bất kỳ tác nhân AI nào đọc được định dạng Agent Skills đều có thể dùng kỹ năng này — hãy sao chép thư mục vào thư mục kỹ năng của tác nhân AI đó.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/dotslashsimran/simcraft.git /tmp/simcraft
mkdir -p .claude/skills
cp -r /tmp/simcraft/skills/video/code-loop .claude/skills/code-loop
Khởi động lại Claude Code sau khi sao chép để ứng dụng nhận kỹ năng mới.

Sử dụng trong TypingMind

Bật Code Loop trong bất kỳ cuộc trò chuyện nào trên TypingMind, mô hình sẽ tự xử lý phần còn lại. Tên và mô tả của kỹ năng nằm trong prompt hệ thống. Ngay khi có yêu cầu phù hợp, mô hình tự tải toàn bộ hướng dẫn — bạn không cần gọi thủ công và kỹ năng không tốn token cho đến khi thực sự được dùng.

Mô hình tự tải Code Loop ngay khi có yêu cầu phù hợp.

Dùng được với mọi mô hình AI

Kỹ năng AI là các hướng dẫn Markdown thuần túy, không phải mã dành riêng cho một nhà cung cấp, nên Code Loop không bị giới hạn ở mô hình mà kỹ năng này được viết cho. Chỉ cần cài đặt một lần trong TypingMind rồi dùng với GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama hoặc mô hình cục bộ do bạn tự chạy — tất cả đều dùng khóa API của riêng bạn.

  • Chỉ tải khi cần

    Prompt hệ thống chỉ chứa tên và mô tả. Hướng dẫn được tải khi có yêu cầu phù hợp đầu tiên, nên kỹ năng chưa dùng không tốn chi phí.

  • Đổi mô hình ngay trong cuộc trò chuyện

    Vì kỹ năng là hướng dẫn chứ không phải mã, việc đổi mô hình không làm kỹ năng ngừng hoạt động — mô hình tiếp theo vẫn đọc cùng tệp SKILL.md.

Hướng dẫn của kỹ năng

Đây là nội dung SKILL.md mà mô hình tải. Hãy đọc trước khi cài đặt — kỹ năng là những hướng dẫn mà mô hình của bạn sẽ làm theo.

Code loop

A loop is seamless only if the frame after the last frame is exactly the first frame, and every motion keeps its speed across that point. The way to get that is to make every frame a pure function of the loop phase, built from motions that complete a whole number of cycles per loop. Then render each frame as an average of many slightly shifted renders, which gives clean edges and real motion blur, and check the result with numbers instead of by eye.

Quick start

mkdir -p loop && cd loop
printf '{"type":"module"}' > package.json && npm i three@0.170.0 playwright@1.60.0
S=<path to this skill>
cp $S/templates/three_starter.html scene.html     # or shader_starter.html for a raw GLSL loop
cp $S/scripts/render_loop.mjs $S/scripts/check_loop.py .
node render_loop.mjs scene.html loop.mp4 --stills=0,2,4,6     # full-quality stills in stills/
node render_loop.mjs scene.html preview.mp4 --preview         # whole loop, half size, 30 fps, seconds to a minute
node render_loop.mjs scene.html final.mp4 --gif               # 60 fps, 8+ samples a frame, plus a GIF
python3 check_loop.py final.mp4 --heat blink.png              # seam, freezes, blinking

Set $FFMPEG if ffmpeg is not on the PATH. Sizes: --size=1920x1080 (default), 1080x1920, 1080x1080, 1080x1350. --loops=3 repeats the loop in the mp4. If a long render is interrupted, run the same command again with --resume.

The page contract

Both starters implement it. Any page that does can be rendered by render_loop.mjs.

HookWhat it does
window.LOOPLoop length in ms. The renderer renders exactly one loop by default.
window.READYSet (or a promise that resolves) once assets, fonts and shaders are ready.
window.render(ms)Draws the frame at time ms.
window.renderMany([[ms, jx, jy], ...])Draws each sub-frame into a float buffer with additive blending at weight 1/n, then tone maps once to the canvas. One screenshot per frame leaves the browser.
window.setJitter(x, y)Sub-pixel offset in canvas pixels. In three.js, add 2x/width and 2y/height to projectionMatrix.elements[8] and [9]. In a shader, add it to gl_FragCoord.xy.
window.probe(ms)Optional. Screen positions [x, y, ndcZ] in output pixels of a few points that move. The renderer uses it to decide how many motion blur samples each frame needs.
?w=&h=&scale=Output size, and a render scale for previews.

The rules of a seamless loop

  1. Everything is a pure function of the phase p = ms / LOOP. No Date.now(), no requestAnimationFrame deltas, no state carried from the last frame, no Math.random() at render time. Seed every random generator, so the preview and the final build the same scene.
  2. Every periodic motion has a whole number of cycles per loop: sin(2π·k·p) with integer k. A rotation turns k full turns, or a whole number of symmetry steps (a 4-fold grid only needs a quarter turn). A texture scrolls a whole number of its widths. A walk cycle repeats a whole number of times.
  3. Loop noise by walking a circle through it. Sample noise(x, y, R·cos 2πp, R·sin 2πp) with 4D noise (or 3D noise for a 1D field). The radius R sets how much it changes over the loop. Adding p to a noise coordinate never loops.
  4. Easing must end where it starts. Use moves that go out and come back (0.5 - 0.5·cos 2πp), or keyframes whose last key equals the first, interpolated with a curve that also matches speed at the wrap (a periodic spline). A plain ease-in-out that stops at the seam reads as a hitch.
  5. Do not wrap ms with % in the page. Periodic maths does not need it, and leaving it unwrapped lets the exact seam test prove the loop is periodic. Wrap only the lookup inside a keyframe track.
  6. The loop length must be a whole number of frames at every frame rate you deliver: 60, 30 (platforms often re-encode to 30) and the GIF rate (25 or 20). 4, 6, 8 and 10 seconds all work.

Why jitter and motion blur

A single render per frame has stair-stepped edges, and thin or distant detail lands on different pixels each frame, so it shimmers and blinks. The renderer instead averages several renders per frame, each shifted by a different sub-pixel offset (a Halton pattern shaped into a tent filter). The same offsets are used every frame, so whatever aliasing is left stays still instead of crawling. When probe says things move fast, the renderer adds more samples spread across the shutter time (up to 32), which turns fast motion into a smooth streak instead of a stutter. Previews use one sample, so they shimmer by design. Judge blinking on finals only.

Craft that decides the quality

  • World-anchored, not screen-anchored. Hatching, grain, noise textures, dither patterns and haze must be attached to the object or the world. Anything fixed to the screen while the scene moves under it crawls and blinks. The one exception is the output dither, which is below one colour step.
  • Telephoto and z-fighting. On long lenses the depth buffer runs out of precision. Keep separate surfaces apart (a few cm at 10 m, more at 400 m), push near out as far as possible, and paint markings onto one surface instead of stacking planes.
  • Colour. Render in linear light into float targets, average there, then tone map, grade and encode to sRGB once at the end. Averaging after sRGB encoding makes blur and anti-aliased edges too dark. Both starters use the Khronos PBR Neutral tone map, a light grade, a vignette and a fixed dither against banding.
  • Speed. Merge static meshes by material at load (mergeStatic in the three starter), and use instancing for many copies. Draw calls, not triangles, are usually the limit.

Workflow

  1. Stills at 4 to 6 phases with --stills. Fix composition, colour and detail here, where each try takes seconds.
  2. Preview with --preview and watch it on loop. Fix timing and motion here.
  3. Final at full quality. Only once the preview is approved.
  4. Check with check_loop.py. It must say PASS. Look at blink.png if anything blinks.

Sharing

WhereSizeNotes
X1920x1080 or 1080x108060 fps is kept. Short clips loop automatically. GIFs up to 15 MB.
Instagram feed1080x1350 (4:5)May be re-encoded to 30 fps. Use --loops so the post is at least a few seconds long.
Reels, TikTok, Shorts1080x1920Keep the subject in the middle, away from the top and bottom fifth, where captions and buttons sit.
GIF480 to 720 px wide, 20 or 25 fps--gif writes one with an ordered dither, which stays still between frames and compresses better than error diffusion.

Fine grain and noise compress badly and turn to mush after a platform re-encode, so keep large smooth shapes and strong contrast.

Building on this engine

perspective-illusion is one style built on this engine: a telephoto line-art scene with dolly zooms, multi-pass ink lines and a scripted camera. Its templates use an earlier form of the same page contract, without window.LOOP and ?w=&h=, and its render_fast.mjs is the ancestor of render_loop.mjs.

Details on each topic, more looping techniques and troubleshooting are in reference.md.

Tệp đi kèm

Mô hình đọc các tệp này khi cần trong lúc kỹ năng được tải. Các tệp được cung cấp ở dạng có thể đọc và không bao giờ được thực thi.

Câu hỏi thường gặp

Kỹ năng AI Code Loop làm được gì?

Make a seamless, perfectly looping generative video in code, from a three.js scene or a raw GLSL fragment shader, rendered frame-perfect with jittered anti-aliasing and motion blur, then checked for a visible seam, freezing and blinking. Use when asked for a "seamless loop", a "perfect loop", "generative art video", a "shader loop", "three.js animation to video", to "render a looping animation", a looping GIF from code, or any code-driven animation that has to loop without a visible cut.

Vì sao nên dùng Code Loop trên TypingMind?

Vì bạn chỉ cần cài một lần rồi dùng với bất kỳ mô hình nào. Code Loop là nội dung Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên cùng một kỹ năng có thể chạy trên GPT-5, Claude, Gemini, Grok hoặc mô hình trên thiết bị — và bạn có thể đổi mô hình ngay trong cuộc trò chuyện mà kỹ năng vẫn hoạt động. TypingMind dùng khóa API riêng của bạn, nên bạn thanh toán trực tiếp cho nhà cung cấp thay vì trả phí thuê bao theo suất người dùng, đồng thời kỹ năng và các cuộc trò chuyện vẫn nằm trong bộ lưu trữ của bạn.

Làm thế nào để cài Code Loop trong TypingMind?

Mở Plugin → Kỹ năng → Cài đặt từ GitHub trong TypingMind rồi dán https://github.com/dotslashsimran/simcraft/tree/main/skills/video/code-loop. TypingMind đọc tệp SKILL.md, đóng gói các tệp đi kèm và cài đặt thành một kỹ năng mà bạn có thể bật cho từng cuộc trò chuyện.

Những mô hình AI nào có thể dùng Code Loop?

Bất kỳ mô hình nào bạn kết nối trong TypingMind. Kỹ năng AI là các hướng dẫn bằng Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên GPT, Claude, Gemini, Grok và các mô hình chạy trên thiết bị đều có thể tải kỹ năng này khi có yêu cầu phù hợp.

Bạn có thể dùng Code Loop với bao nhiêu mô hình AI?

Bao nhiêu cũng được. Miễn là mô hình hỗ trợ kỹ năng, bạn có thể dùng Code Loop với mô hình đó — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama và nhiều mô hình khác — tất cả đều trên TypingMind với khóa API riêng của bạn.

Kỹ năng AI Code Loop có miễn phí không?

Có. Kỹ năng này được dotslashsimran phát hành trên GitHub theo giấy phép MIT. Bạn chỉ trả tiền cho nhà cung cấp AI của mình theo số token đã dùng.

Kỹ năng AI là gì?

Kỹ năng AI là một gói hướng dẫn có thể tái sử dụng, chỉ cho mô hình AI cách thực hiện một tác vụ cụ thể. Kỹ năng tuân theo định dạng mở Agent Skills: một tệp SKILL.md chứa tên và mô tả, cùng các tập lệnh, mẫu hoặc tệp tham khảo mà mô hình có thể cần. Mô hình chỉ đọc hướng dẫn khi yêu cầu của bạn phù hợp với kỹ năng, nên kỹ năng đã cài đặt không phát sinh chi phí cho đến khi được sử dụng.

Kỹ năng AI khác gì với plugin hoặc máy chủ MCP?

Plugin hoặc máy chủ MCP cung cấp cho mô hình các công cụ mới để gọi — mã được chạy ở đâu đó và trả về kết quả. Còn kỹ năng AI cung cấp kiến thức và quy trình: cách tiếp cận tác vụ, các bước cần thực hiện và tiêu chí của đầu ra tốt. Kỹ năng chỉ là nội dung Markdown, nên không cần máy chủ, khóa API hay môi trường thực thi và hoạt động với mọi mô hình.

Xem tất cả

Tạo ngay không gian làm việc AI riêng

Đăng ký bản tin của chúng tôi để nhận thông báo về tính năng mới và các đợt tặng quà sắp tới 👇