Penulisan Kode Animasi alomotion
Pelajari struktur Mode JS (.js) dan Mode HTML (.html), referensi lengkap fungsi AM.* serta audio.*, dan salin template siap render.
1. Dua Format Kode yang Didukung
Setiap proyek video di alomotion adalah 1 file tunggal di folder compositions/ (bisa ditulis langsung di editor Studio atau di-upload dari HP/PC).
Deterministik Frame-by-Frame
Mesin memanggil render(ctx) untuk frame 0 sampai frame terakhir. Mendukung multi-worker parallel rendering dan sinkronisasi penuh beat/bass MP3.
Aturan Wajib: Jangan gunakan setTimeout, setInterval, atau CSS @keyframes. Hitung semua gerakan dari frame.
File HTML / CSS / Canvas Standar
Tambahkan tag <meta name="alomotion" content="width=1080,height=1920,fps=30,duration=6" /> di <head>. Virtual clock otomatis mengunci @keyframes dan requestAnimationFrame agar nol frame drop.
2. Struktur Dasar Mode JS
Setiap komposisi .js wajib mengekspor config dan fungsi render(ctx):
export const config = {
width: 1080, // Lebar piksel (harus genap)
height: 1920, // Tinggi piksel (harus genap)
fps: 30, // 24, 30, atau 60
durationInFrames: 300, // Total frame (300 @ 30fps = 10 detik)
};
export function render({
frame, // Nomor frame saat ini: 0 .. durationInFrames - 1
fps, // Frame rate
durationInFrames, // Total durasi dalam frame
width, // Lebar kanvas (px)
height, // Tinggi kanvas (px)
progress, // Progres global: 0.0 .. 1.0
timeSec, // Waktu saat ini dalam detik (frame / fps)
root, // Elemen DOM #stage tempat menulis HTML/SVG
audio, // Data FFT audio untuk frame ini
AM, // SDK animasi deterministik alomotion
}) {
// Hitung seluruh animasi dari frame & render ke root.innerHTML
}3. Referensi SDK AM.*
Objek AM disuntikkan otomatis ke fungsi render tanpa perlu import manual.
| Fungsi | Signature | Fungsi & Kegunaan |
|---|---|---|
AM.spring | ({ frame, fps, from, to, delay, config }) | Animasi pegas fisika analitik (damping, stiffness, mass). |
AM.interpolate | (val, [in0, in1], [out0, out1], opts) | Memetakan nomor frame ke posisi, skala, rotasi, atau opacity dengan easing. |
AM.Easing | snappy, punchy, easeOutExpo, bezier(...) | Kurva percepatan ala Graph Editor After Effects. |
AM.sequence | (frame, fromFrame, duration) | Mengembalikan { active, localFrame, progress } untuk membagi scene. |
AM.stagger | (frame, index, stepFrames) | Memberi jeda masuk berurutan untuk kata atau elemen list. |
AM.interpolateColors | (progress, [0, 1], ['#090A0C', '#2E8BFF']) | Transisi warna halus dalam format RGB. |
AM.random | (seed) → 0..1 | Angka acak deterministik (identik di semua parallel worker). |
AM.delayRender | delayRender() / continueRender(id) | Menahan capture frame hingga aset async selesai dimuat. |
4. Referensi Objek audio.* (Offline FFT)
Saat file MP3/WAV dipasang di tab Comp & Audio, FFmpeg mengekstrak PCM & Radix-2 FFT untuk setiap frame:
| Properti | Tipe & Rentang | Deskripsi |
|---|---|---|
audio.hasAudio | boolean | true jika track audio aktif terpasang. |
audio.rms | 0.0 – 1.0 | Volume keseluruhan frame saat ini. |
audio.bass | 0.0 – 1.0 | Energi frekuensi rendah (20–220 Hz) untuk efek kick/pulse. |
audio.mid / treble | 0.0 – 1.0 | Energi vokal/instrumen tengah & frekuensi tinggi. |
audio.beat | 0 atau 1 | Deteksi onset hentakan bass/drum otomatis. |
audio.bars | number[24] | 24 band spektrum logaritmik (40Hz–12kHz) untuk visualizer. |
5. Contoh Template Lengkap Siap Pakai
Pilih template di bawah, salin kodenya, tempel di Studio alomotion, lalu langsung render ke MP4.
export const config = {
width: 1080,
height: 1920,
fps: 30,
durationInFrames: 300, // 10 detik @ 30fps
};
const LYRICS = [
{ start: 0.0, end: 3.3, text: 'Sisa silam masih melekat', tag: '01 // INTRO' },
{ start: 3.3, end: 6.6, text: 'Di dalam benak tertera', tag: '02 // VERSE' },
{ start: 6.6, end: 10.0, text: 'Tatkala mentarimu datang', tag: '03 // CHORUS' },
];
export function render({ frame, fps, width, height, timeSec, root, audio, AM }) {
const cue = LYRICS.find((c) => timeSec >= c.start && timeSec < c.end)
|| LYRICS[LYRICS.length - 1];
const localFrame = Math.max(0, frame - Math.round(cue.start * fps));
const bass = audio.hasAudio
? audio.bass
: 0.25 + 0.2 * Math.abs(Math.sin(frame * 0.2));
const bars = audio.hasAudio
? audio.bars
: Array.from({ length: 20 }, (_, i) => 0.2 + 0.6 * Math.abs(Math.sin(frame * 0.16 + i * 0.4)));
const list = cue.text.split(' ');
const words = list.map((word, idx) => {
const wf = AM.stagger(localFrame, idx, 3);
const s = AM.spring({ frame: wf, fps, config: { damping: 12, stiffness: 200 } });
const y = AM.interpolate(s, [0, 1], [85, 0]);
const hl = idx === list.length - 1
? 'background:#2E8BFF;color:#fff;padding:6px 24px;border-radius:12px;'
: '';
return `<span style="display:inline-block;transform:translateY(${y.toFixed(1)}px);opacity:${AM.clamp(s * 1.4).toFixed(2)};margin:6px 10px;${hl}">${word}</span>`;
}).join('');
const eq = bars.slice(0, 20).map((v) =>
`<div style="flex:1;height:${Math.max(10, Math.round(v * 90))}px;background:#2E8BFF;border-radius:3px;"></div>`
).join('');
root.innerHTML = `
<div style="width:${width}px;height:${height}px;background:#0B0C0E;color:#F5F7FA;padding:88px 72px;display:flex;flex-direction:column;justify-content:space-between;font-family:'Inter',sans-serif;">
<div style="font-family:monospace;font-size:24px;color:#6DB0FF;display:flex;justify-content:space-between;">
<span>${cue.tag}</span><span>${timeSec.toFixed(2)}s</span>
</div>
<div style="text-align:center;font-size:76px;font-weight:900;line-height:1.12;letter-spacing:-2px;transform:scale(${(1 + bass * 0.08).toFixed(3)});">
${words}
</div>
<div style="display:flex;align-items:flex-end;gap:8px;height:96px;">${eq}</div>
</div>`;
}export const config = {
width: 1920,
height: 1080,
fps: 30,
durationInFrames: 180, // 6 detik @ 30fps
};
export function render({ frame, fps, width, height, root, AM }) {
const s1 = AM.sequence(frame, 0, 80);
const s2 = AM.sequence(frame, 80, 100);
if (s1.active) {
const pop = AM.spring({ frame: s1.localFrame, fps, config: { damping: 13, stiffness: 170 } });
const outOp = AM.interpolate(s1.localFrame, [66, 80], [1, 0], {
extrapolateLeft: 'clamp', extrapolateRight: 'clamp',
});
root.innerHTML = `
<div style="width:${width}px;height:${height}px;background:#090A0C;color:#F5F7FA;display:grid;place-items:center;font-family:'Space Grotesk',sans-serif;">
<div style="text-align:center;opacity:${outOp.toFixed(2)};transform:translateY(${((1 - pop) * 70).toFixed(1)}px);">
<div style="font-family:monospace;font-size:26px;color:#6DB0FF;letter-spacing:4px;margin-bottom:20px;">ALOMOTION.MY.ID</div>
<h1 style="font-size:112px;font-weight:800;letter-spacing:-4px;">Render Dari Kode.</h1>
</div>
</div>`;
return;
}
const card = AM.spring({ frame: s2.localFrame, fps, config: { damping: 14, stiffness: 150 } });
const fpsNum = Math.round(AM.interpolate(s2.localFrame, [10, 60], [0, 60], {
extrapolateLeft: 'clamp', extrapolateRight: 'clamp', easing: AM.Easing.easeOutExpo,
}));
root.innerHTML = `
<div style="width:${width}px;height:${height}px;background:#F4F5F7;color:#0E0F12;display:grid;place-items:center;font-family:'Inter',sans-serif;">
<div style="width:1180px;padding:72px;border-radius:24px;background:#fff;border:3px solid #E4E6EB;transform:scale(${(0.88 + card * 0.12).toFixed(3)});">
<div style="font-family:monospace;font-size:24px;color:#646C7A;">OUTPUT MODULE · H.264 MP4</div>
<div style="font-size:148px;font-weight:900;letter-spacing:-6px;color:#2E8BFF;line-height:1;margin:20px 0;">${fpsNum} FPS</div>
<div style="font-size:32px;color:#3F4450;">Presisi frame demi frame via Chromium CDP & FFmpeg.</div>
</div>
</div>`;
}<!DOCTYPE html>
<html lang="id">
<head>
<meta charset="UTF-8" />
<meta name="alomotion" content="width=1080,height=1920,fps=30,duration=6" />
<title>Template HTML alomotion</title>
<style>
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
width: 100vw; height: 100vh; overflow: hidden;
background: #090a0c; color: #f5f7fa;
font-family: system-ui, sans-serif;
display: grid; place-items: center;
}
.card {
width: 820px; padding: 68px; border-radius: 20px;
background: #12151c; border: 3px solid #262b36;
animation: slideIn 0.8s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}
.tag {
display: inline-block; padding: 8px 20px; border-radius: 6px;
background: #2e8bff; font-family: monospace; font-size: 24px;
font-weight: 700; margin-bottom: 28px;
}
h1 { font-size: 96px; font-weight: 900; letter-spacing: -3px; line-height: 1; margin-bottom: 20px; }
p { font-size: 30px; color: #9ba3b0; }
@keyframes slideIn {
from { opacity: 0; transform: translateY(90px) scale(0.92); }
to { opacity: 1; transform: translateY(0) scale(1); }
}
</style>
</head>
<body>
<div class="card" id="card">
<div class="tag">HTML VIRTUAL CLOCK</div>
<h1>alomotion</h1>
<p>File HTML + CSS @keyframes standar langsung render MP4.</p>
</div>
<script>
// Hook opsional untuk sinkronisasi bass audio MP3
window.onAloMotionFrame = ({ timeSec, audio }) => {
if (timeSec > 0.85 && audio && audio.hasAudio) {
const el = document.getElementById('card');
el.style.animation = 'none';
el.style.transform = `scale(${(1 + audio.bass * 0.1).toFixed(3)})`;
}
};
</script>
</body>
</html>6. Membuat Kode Animasi dengan AI via /llms.txt
Tidak ingin menulis animasi dari nol? Salin prompt di bawah ini atau berikan link https://alomotion.my.id/llms.txt ke Gemini, Claude, atau ChatGPT agar AI menghasilkan kode yang 100% sesuai standar alomotion.
Pelajari dokumentasi alomotion di https://alomotion.my.id/llms.txt lalu buatkan 1 file JavaScript ES Module (.js) untuk alomotion:
1. Export config: export const config = { width: 1080, height: 1920, fps: 30, durationInFrames: 300 };
2. Export render({ frame, fps, durationInFrames, width, height, timeSec, root, audio, AM }).
3. Dilarang memakai setTimeout, setInterval, atau CSS @keyframes. Hitung semua animasi dari frame menggunakan AM.spring, AM.interpolate, AM.Easing, AM.sequence, AM.stagger, dan audio.bass / audio.bars.
4. Render seluruh tampilan tepat berukuran width x height px ke root.innerHTML.
Tema / lirik video yang saya inginkan: [TULIS IDE VIDEO DI SINI]