Tutorials & Guides

This section contains step-by-step tutorials and comprehensive guides for using CodeVideoRenderer.

Getting Started

Quick Start Guide

Create your first code animation video:

from CodeVideoRenderer import CameraFollowCursorCV

code = '''
def hello_world():
    print("Hello, World!")
    return True
'''

# Create a simple code animation
video = CameraFollowCursorCV(
    code=('string', code),
    language='python',
    formatter_style='github-dark'
)

video.render()

Basic Concepts

Understanding CodeVideoRenderer

CodeVideoRenderer works by:

  1. Parsing Code: Reads and processes your code

  2. Syntax Highlighting: Applies language-specific coloring

  3. Animation: Creates typing animations character by character

  4. Camera Movement: Smoothly follows the cursor

Core Components

  • CameraFollowCursorCV: Main class for creating animations

  • Code Input: Support for strings and files

  • Renderer Types: Cairo (software) and OpenGL (hardware accelerated)

Intermediate Tutorials

Customizing Animation Speed

Control the typing speed with interval ranges:

video = CameraFollowCursorCV(
    code=('string', 'your_code_here'),
    language='python',
    interval_range=(0.05, 0.1),  # Fast typing
    # interval_range=(0.2, 0.5),  # Slow, deliberate typing
)

Working with Files

Animate code from existing files:

video = CameraFollowCursorCV(
    code=('file', 'path/to/your/script.py'),
    language='python',
    video_name='MyScriptAnimation'
)

Advanced Tutorials

Custom Styling

Use different syntax highlighting styles:

# Available styles: github-dark, monokai, solarized-dark, etc.
video = CameraFollowCursorCV(
    code=('string', 'code'),
    language='python',
    formatter_style='monokai'
)

Camera Configuration

Adjust camera behavior for different code sizes:

video = CameraFollowCursorCV(
    code=('string', 'large_code_block'),
    language='python',
    camera_scale=0.3,  # Zoom out for large files
    line_spacing=1.2   # Increase spacing for readability
)

Best Practices

Code Preparation

  • Clean Code: Remove unnecessary comments and whitespace

  • Consistent Formatting: Use consistent indentation

  • Reasonable Length: Keep code blocks under 100 lines for optimal viewing

Switching to OpenGL

By default CodeVideoRenderer uses the Cairo (CPU) backend. If you have a compatible GPU, you can switch to OpenGL for faster rendering:

video = CameraFollowCursorCV(
    code=('string', 'your_code_here'),
    language='python',
    renderer='opengl'  # Use GPU acceleration
)
video.render()

Note

OpenGL support depends on your graphics drivers and operating system. If rendering fails with OpenGL, fall back to renderer='cairo' (the default).

Controlling Console Output

By default render() prints progress bars and timing logs. To run silently:

video.render(output=False)

This is useful when rendering in CI/CD pipelines or batch scripts where console noise should be minimized.

Performance Optimization

  • Use OpenGL: For faster rendering on supported systems (see example above)

  • Batch Processing: Render multiple videos in sequence

  • Resolution: Choose appropriate resolution for your needs

Troubleshooting Common Issues

See the FAQ & Troubleshooting section for solutions to common problems (FFmpeg errors, invalid characters, slow rendering, etc.).