Skip to content

🎥 Make videos programmatically with React

Tune system prompt

ASchwadcc54eb5fa6c5
diff --git a/packages/template-code-generation/src/app/api/generate/route.ts b/packages/template-code-generation/src/app/api/generate/route.ts
index bbd976045f..28e3db753f 100644
--- a/packages/template-code-generation/src/app/api/generate/route.ts
+++ b/packages/template-code-generation/src/app/api/generate/route.ts
@@ -4,19 +4,8 @@ import { createOpenAI } from "@ai-sdk/openai";
const SYSTEM_PROMPT = `
You are an expert in generating React components for Remotion animations.
-IMPORTANT RULES:
-1. Start the code with a multi-line comment (/* */) containing a 2-3 sentence description of what you're building
-2. Do NOT include any imports - they are provided automatically
-3. Available APIs: React, AbsoluteFill, interpolate, useCurrentFrame, useVideoConfig, spring, Sequence
-4. Use creative animations with smooth transitions
-5. Component should use frame-based animations with interpolate()
-6. Make it visually impressive and modern
-7. Use inline styles for all styling
-8. ALWAYS use fontFamily: 'Inter, sans-serif' for ALL text elements to ensure consistent rendering
-9. Do not define the component name - start directly with the comment, then the code
-
LAYOUT RULES:
-- For diagrams, charts, flowcharts, or any data visualizations: USE THE FULL WIDTH of the container
+- ALWAYS USE THE FULL WIDTH of the container
- Ensure diagrams span edge-to-edge with appropriate padding (e.g., padding: 40px)
- Never constrain diagrams to a small centered box - maximize the visual space
@@ -42,7 +31,6 @@ ANIMATION TIMING RULES:
const ANIMATION_SPEED = 1.0; // Speed multiplier (1.0 = normal, 2.0 = 2x faster)
const FADE_DURATION = 20; // Duration in frames
const ELEMENT_DELAY = 5; // Delay between elements in frames
- const ROTATION_SPEED = 180; // Degrees of rotation
ADDITIONAL CONSTANTS TO DEFINE:
- Typography: FONT_SIZE, FONT_WEIGHT, LETTER_SPACING
@@ -327,6 +315,206 @@ return (
</div>
</AbsoluteFill>
);
+
+---
+
+EXAMPLE 4: Animated bar chart / histogram
+
+Prompt: "An animated histogram with the gold price. Focus on simplicity and elegance. Small headline, all bars are well laid out"
+
+/*
+ * Elegant animated bar chart showing gold prices with Y-axis, staggered spring animations, and full-width layout.
+ */
+const frame = useCurrentFrame();
+const { fps, height: videoHeight } = useVideoConfig();
+
+const TITLE = "Gold Price 2024";
+const UNIT = "USD per troy ounce";
+const COLOR_BAR = "#D4AF37";
+const COLOR_TEXT = "#ffffff";
+const COLOR_MUTED = "#888888";
+const COLOR_BG = "#0a0a0a";
+const COLOR_AXIS = "#333333";
+
+const PADDING = 50;
+const HEADER_HEIGHT = 70;
+const LABEL_HEIGHT = 32;
+const BAR_GAP = 8;
+const BAR_RADIUS = 4;
+const TITLE_FONT_SIZE = 24;
+const LABEL_FONT_SIZE = 11;
+const VALUE_FONT_SIZE = 11;
+const AXIS_FONT_SIZE = 12;
+const STAGGER_DELAY = 5;
+const HEADER_START_FRAME = 0;
+const BARS_START_FRAME = 10;
+const SPRING_DAMPING = 18;
+const SPRING_STIFFNESS = 80;
+
+const data = [
+ { month: "Jan", price: 2039 },
+ { month: "Feb", price: 2024 },
+ { month: "Mar", price: 2160 },
+ { month: "Apr", price: 2330 },
+ { month: "May", price: 2327 },
+ { month: "Jun", price: 2339 },
+ { month: "Jul", price: 2426 },
+ { month: "Aug", price: 2503 },
+ { month: "Sep", price: 2634 },
+ { month: "Oct", price: 2735 },
+ { month: "Nov", price: 2672 },
+ { month: "Dec", price: 2650 },
+];
+
+const minPrice = 1900;
+const maxPrice = 2800;
+const priceRange = maxPrice - minPrice;
+const chartHeight = videoHeight - (PADDING * 2) - HEADER_HEIGHT - LABEL_HEIGHT;
+const yAxisSteps = [1900, 2100, 2300, 2500, 2700];
+
+const headerOpacity = spring({
+ frame: frame - HEADER_START_FRAME,
+ fps,
+ config: { damping: 20, stiffness: 100 },
+});
+
+return (
+ <AbsoluteFill
+ style={{
+ backgroundColor: COLOR_BG,
+ padding: PADDING,
+ display: "flex",
+ flexDirection: "column",
+ fontFamily: "Inter, sans-serif",
+ }}
+ >
+ {/* Header */}
+ <div style={{ height: HEADER_HEIGHT, opacity: headerOpacity, marginBottom: 10 }}>
+ <div style={{ color: COLOR_TEXT, fontSize: TITLE_FONT_SIZE, fontWeight: 600 }}>{TITLE}</div>
+ <div style={{ color: COLOR_MUTED, fontSize: 14, marginTop: 4 }}>{UNIT}</div>
+ </div>
+
+ {/* Chart container */}
+ <div style={{ display: "flex", alignItems: "flex-end", width: "100%", flex: 1 }}>
+ {/* Y-Axis */}
+ <div
+ style={{
+ display: "flex",
+ flexDirection: "column",
+ justifyContent: "space-between",
+ height: chartHeight,
+ paddingRight: 12,
+ marginBottom: LABEL_HEIGHT,
+ }}
+ >
+ {yAxisSteps.slice().reverse().map((step) => (
+ <div
+ key={step}
+ style={{
+ color: COLOR_MUTED,
+ fontSize: AXIS_FONT_SIZE,
+ textAlign: "right",
+ minWidth: 40,
+ }}
+ >
+ {step.toLocaleString()}
+ </div>
+ ))}
+ </div>
+
+ {/* Chart area */}
+ <div
+ style={{
+ display: "flex",
+ alignItems: "flex-end",
+ gap: BAR_GAP,
+ height: chartHeight,
+ flex: 1,
+ borderLeft: \`1px solid \${COLOR_AXIS}\`,
+ borderBottom: \`1px solid \${COLOR_AXIS}\`,
+ paddingLeft: 8,
+ }}
+ >
+ {data.map((item, i) => {
+ const delay = i * STAGGER_DELAY;
+ const progress = spring({
+ frame: frame - delay - BARS_START_FRAME,
+ fps,
+ config: { damping: SPRING_DAMPING, stiffness: SPRING_STIFFNESS },
+ });
+
+ const normalizedHeight = ((item.price - minPrice) / priceRange) * chartHeight;
+ const height = normalizedHeight * progress;
+
+ return (
+ <div
+ key={i}
+ style={{
+ textAlign: "center",
+ flex: 1,
+ height: "100%",
+ display: "flex",
+ flexDirection: "column",
+ justifyContent: "flex-end",
+ }}
+ >
+ <div
+ style={{
+ width: "100%",
+ height,
+ backgroundColor: COLOR_BAR,
+ borderRadius: \`\${BAR_RADIUS}px \${BAR_RADIUS}px 0 0\`,
+ display: "flex",
+ justifyContent: "center",
+ alignItems: "flex-start",
+ paddingTop: 6,
+ minHeight: height > 0 ? 4 : 0,
+ }}
+ >
+ {height > 30 && (
+ <span
+ style={{
+ color: COLOR_BG,
+ fontSize: VALUE_FONT_SIZE,
+ fontWeight: 600,
+ opacity: progress,
+ }}
+ >
+ {item.price.toLocaleString()}
+ </span>
+ )}
+ </div>
+ <div
+ style={{
+ color: COLOR_MUTED,
+ fontSize: LABEL_FONT_SIZE,
+ marginTop: 8,
+ height: LABEL_HEIGHT - 8,
+ }}
+ >
+ {item.month}
+ </div>
+ </div>
+ );
+ })}
+ </div>
+ </div>
+ </AbsoluteFill>
+);
+
+----
+END OF EXAMPLES
+
+IMPORTANT RULES:
+1. Start the code with a multi-line comment (/* */) containing a 2-3 sentence description of what you're building
+2. NEVER include imports or exports - they are provided automatically
+3. Available APIs: React, AbsoluteFill, interpolate, useCurrentFrame, useVideoConfig, spring, Sequence
+4. Use creative animations with smooth transitions
+5. Component should use frame-based animations with interpolate()
+6. Make it visually impressive and modern
+7. Use inline styles for all styling
+8. ALWAYS use fontFamily: 'Inter, sans-serif' for ALL text elements to ensure consistent rendering
+9. Do not define the component name - start directly with the comment, then the code
`;
export async function POST(req: Request) {