Skip to main content
Glama
theme_switching_demo.py9.81 kB
#!/usr/bin/env python3 """ Theme Switching Demonstration ============================== Demonstrates how the tokenized design system allows seamless theme switching. Shows the same components rendered with different themes to highlight the power of design tokens. This example creates a video that: 1. Shows the same chart/code/overlay components 2. Switches between different themes (Tech, Finance, Education, etc.) 3. Demonstrates how all tokens (colors, typography, motion) change together Usage: python examples/theme_switching_demo.py """ import asyncio from chuk_motion.themes.youtube_themes import YOUTUBE_THEMES async def create_theme_comparison(): """Create a video comparing different themes.""" print("=" * 80) print("THEME SWITCHING DEMONSTRATION") print("=" * 80) print() # List available themes print("Available themes:") for theme_name in YOUTUBE_THEMES.themes.keys(): theme = YOUTUBE_THEMES.themes[theme_name] print(f" • {theme.name}: {theme.description}") print(f" Primary: {theme.colors.primary[0]}, Accent: {theme.colors.accent[0]}") print() # Create compositions for each theme themes_to_demo = ["tech", "finance", "education", "lifestyle", "gaming"] print("Creating theme comparison video...") print() # Common data for consistent comparison chart_data = [ {"label": "Jan", "value": 4200}, {"label": "Feb", "value": 5100}, {"label": "Mar", "value": 6300}, {"label": "Apr", "value": 5800}, {"label": "May", "value": 7200}, ] code_sample = """function calculateMetrics(data) { const total = data.reduce((sum, item) => sum + item.value, 0 ); return { total, average: total / data.length, max: Math.max(...data.map(d => d.value)) }; }""" # Track configuration for all themes all_tracks = [] start_time = 0 scene_duration = 6 # seconds per theme for theme_name in themes_to_demo: theme = YOUTUBE_THEMES.themes[theme_name] print(f"\nCreating scene for {theme.name} theme...") print(f" Colors: {theme.colors.primary[0]} / {theme.colors.accent[0]}") print(f" Spring: {theme.motion.default_spring}") print(f" Typography: {theme.typography.primary_font.name}") # Create a track for this theme showing multiple components theme_tracks = [ # Title card { "type": "text_overlay", "text": f"{theme.name} Theme", "position": "top", "start_time": start_time, "duration": scene_duration, "animation": "fade_in", }, # Subtitle { "type": "text_overlay", "text": theme.description, "position": "center", "start_time": start_time + 0.3, "duration": scene_duration - 0.3, "animation": "slide_up", "style": { "fontSize": "32px", "opacity": 0.8, } }, # Bar chart with theme colors { "type": "bar_chart", "data": chart_data, "title": "Monthly Performance", "start_time": start_time + 1.0, "duration": scene_duration - 1.0, }, # Code block with theme styling { "type": "code_block", "code": code_sample, "language": "javascript", "title": "metrics.js", "variant": "editor", "start_time": start_time + 2.5, "duration": scene_duration - 2.5, "position": {"x": "center", "y": "bottom"}, }, # Lower third overlay { "type": "lower_third", "name": f"{theme.name} Design System", "title": "Powered by Design Tokens", "start_time": start_time + 4.0, "duration": scene_duration - 4.0, }, ] all_tracks.extend(theme_tracks) start_time += scene_duration # Create the final composition total_duration = len(themes_to_demo) * scene_duration print(f"\nGenerating video:") print(f" Duration: {total_duration} seconds") print(f" Themes: {len(themes_to_demo)}") print(f" Components per theme: 5") print(f" Total tracks: {len(all_tracks)}") # Configuration config = { "composition_name": "ThemeSwitchingDemo", "width": 1920, "height": 1080, "fps": 30, "duration_frames": int(total_duration * 30), "theme": "tech", # Start with tech theme "tracks": all_tracks, } print(f"\nConfiguration:") print(f" Resolution: {config['width']}x{config['height']}") print(f" FPS: {config['fps']}") print(f" Total frames: {config['duration_frames']}") return config async def demo_token_usage(): """Demonstrate how to access and use tokens programmatically.""" print("\n" + "=" * 80) print("TOKEN USAGE EXAMPLES") print("=" * 80) print() print("1. Accessing theme colors:") print("```python") print("tech_theme = YOUTUBE_THEMES.themes['tech']") print("primary_color = tech_theme.colors.primary[0] # '#0066FF'") print("accent_color = tech_theme.colors.accent[0] # '#00D9FF'") print("background = tech_theme.colors.background.dark # '#0A0E1A'") print("```") print() print("2. Using typography tokens:") print("```python") print("title_font = tech_theme.typography.primary_font.fonts") print("# ['Inter', 'SF Pro Display', 'Helvetica Neue', 'system-ui', 'sans-serif']") print() print("font_size = tech_theme.typography.default_resolution") print("# Access via: typography.font_sizes[font_size].xl") print("```") print() print("3. Applying motion tokens:") print("```python") print("spring = tech_theme.motion.default_spring") print("# 'smooth' - gets MOTION_TOKENS.spring_configs['smooth']") print() print("duration = tech_theme.motion.default_duration") print("# 'normal' - gets MOTION_TOKENS.duration['normal']") print("```") print() print("4. Full theme context:") print("```python") print("# All components receive these tokens automatically") print("context = {") print(" 'colors': tech_theme.colors,") print(" 'typography': tech_theme.typography,") print(" 'motion': tech_theme.motion,") print(" 'spacing': tech_theme.spacing,") print("}") print("```") print() async def show_theme_differences(): """Show specific differences between themes.""" print("=" * 80) print("THEME COMPARISON TABLE") print("=" * 80) print() themes = ["tech", "finance", "education", "lifestyle", "gaming"] # Header print(f"{'Theme':<12} {'Primary':<10} {'Accent':<10} {'Spring':<10} {'Font':<15}") print("-" * 70) for theme_name in themes: theme = YOUTUBE_THEMES.themes[theme_name] primary = theme.colors.primary[0] accent = theme.colors.accent[0] spring = str(theme.motion.default_spring) font = theme.typography.primary_font.name print(f"{theme.name:<12} {primary:<10} {accent:<10} {spring:<10} {font:<15}") print() print("Key Observations:") print(" • Each theme has unique primary/accent colors") print(" • Motion springs vary: 'smooth' (tech) vs 'bouncy' (education)") print(" • Typography changes: Display fonts (tech) vs Decorative (lifestyle)") print(" • All tokens work together for cohesive brand experience") print() async def main(): """Run the theme switching demonstration.""" # Show token usage examples await demo_token_usage() # Show theme comparison table await show_theme_differences() # Create the theme comparison config config = await create_theme_comparison() print("\n" + "=" * 80) print("NEXT STEPS") print("=" * 80) print() print("To render this video:") print(" 1. Save the configuration to a file") print(" 2. Use the Remotion CLI to render each theme") print(" 3. Compare the visual differences!") print() print("Example render command:") print(" npx remotion render ThemeSwitchingDemo output.mp4") print() print("What you'll see:") print(" • Same data, different visual treatment") print(" • Colors change per theme (primary/accent/backgrounds)") print(" • Typography shifts (fonts, sizes, weights)") print(" • Motion feels different (spring animations)") print(" • Spacing and borders adapt automatically") print() print("This demonstrates the power of design tokens:") print(" ✓ Change theme = instant rebrand") print(" ✓ No hardcoded values anywhere") print(" ✓ Consistent design system") print(" ✓ Easy to maintain and scale") print() return config if __name__ == "__main__": result = asyncio.run(main()) print("=" * 80) print("DEMO COMPLETE!") print("=" * 80) print() print("Key Takeaways:") print(" 1. All 28 components now use design tokens") print(" 2. 0 hardcoded rgba() colors remaining") print(" 3. 0 hardcoded hex colors (except theme variants)") print(" 4. 100% theme-aware design system") print() print("Try it yourself:") print(" • Modify a theme color → see all components update") print(" • Change typography → entire video reflows") print(" • Adjust motion → feel changes globally") print()

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/chrishayuk/chuk-mcp-remotion'

If you have feedback or need assistance with the MCP directory API, please join our Discord server