CameraFollowCursorCV¶
CameraFollowCursorCV is the primary class for creating code typing animation videos. It handles code parsing, syntax highlighting, camera movement, and the full rendering pipeline.
Quick Example¶
from CodeVideoRenderer import CameraFollowCursorCV
video = CameraFollowCursorCV(
code=('string', 'print("Hello, World!")'),
language='python',
video_name='HelloWorld'
)
video.render()
Constructor Parameters¶
The following table summarizes the parameters accepted by the constructor. For the complete signature, see the API reference below.
Parameter |
Default |
Description |
|---|---|---|
|
required |
A tuple |
|
required |
Programming language for syntax highlighting (e.g. |
|
|
Pygments style name (e.g. |
|
|
Vertical spacing between code lines. |
|
|
Min/max seconds between typed characters. |
|
|
Initial camera zoom level. |
|
|
Base name of the output MP4 file (without extension). |
|
|
Rendering backend: |
Output¶
After calling render(), the final video is saved as an MP4 file. The default location follows Manim’s output convention:
./media/videos/1080p60/{video_name}.mp4
The exact sub-directory (e.g. 1080p60) depends on Manim’s quality configuration. The file name is determined by the video_name parameter you passed to the constructor.
Full API Reference¶
- class CodeVideoRenderer.renderer.CameraFollowCursorCV(code: Tuple[Literal['string'], str] | Tuple[Literal['file'], StrPath], language: PygmentsLanguage, formatter_style: PygmentsFormatterStyle = 'material', line_spacing: float | int = 0.8, interval_range: Tuple[float | int, float | int] = (0.15, 0.15), camera_scale: float | int = 0.5, video_name: str = 'CameraFollowCursorCV', renderer: Literal['cairo', 'opengl'] = 'cairo')[source]¶
Bases:
objectCameraFollowCursorCV is a class designed to create animated videos that simulate the process of typing code. It animates code line by line and character by character while smoothly moving the camera to follow the cursor, creating a professional-looking coding demonstration.
- Parameters:
code (Union[Tuple[Literal['string'], str], Tuple[Literal['file'], StrPath]]) – The code to be animated. When using a string, provide a tuple with the first element as
'string'and the second element as the code string. When using a file, provide a tuple with the first element as'file'and the second element as the file path.language (PygmentsLanguage) – The programming language of the code.
formatter_style (PygmentsFormatterStyle) – The style for syntax highlighting. Defaults to
"material".line_spacing (Union[float, int]) – The line spacing for the code. Defaults to
DEFAULT_LINE_SPACING.interval_range (Tuple[Union[float, int], Union[float, int]]) – The range of typing intervals between characters. Defaults to (
DEFAULT_TYPE_INTERVAL,DEFAULT_TYPE_INTERVAL).camera_scale (Union[float, int]) – The scale factor for the camera. Defaults to 0.5.
video_name (str) – The name of the output video file. Defaults to
"CameraFollowCursorCV".renderer (Literal['cairo', 'opengl']) – The renderer to use for video rendering. Defaults to
'cairo'.
- render(output: bool = True)[source]¶
Render the animated code video.
This method triggers the full rendering pipeline:
Manim rendering – the code typing animation is rendered using the configured backend (Cairo or OpenGL).
Glow effect – a soft glow post-processing effect is applied to the raw video via MoviePy.
The final video file is saved next to Manim’s default output path with the name specified by
video_name.- Parameters:
output (bool) – Whether to print progress messages and timing logs to the console during rendering. Defaults to
DEFAULT_OUTPUT_VALUE.- Returns:
None
Example
>>> video = CameraFollowCursorCV( ... code=('string', 'print("Hello")'), ... language='python', ... video_name='HelloWorld' ... ) >>> video.render()
Note
The final MP4 file is typically located at
./media/videos/1080p60/{video_name}.mp4(the exact sub-directory depends on Manim’s quality configuration).