Skip to content

Examples

github-actions[bot] edited this page Sep 20, 2026 · 15 revisions

Examples

examples/. Each example is one program that renders one image or animation into out/. make animation renders them all.

Run one by hand:

mkdir -p out
.venv/bin/mojo run -I . examples/cubes.mojo out/cubes.png
Example Output Page
triangle.mojo triangle.png The smallest program that draws.
spin.mojo spin.png Image files
cube.mojo cube.png Why a software rasterizer
cubes.mojo cubes.png Scene graph
uv.mojo uv.png Why interpolation is perspective-correct
textured.mojo textured.png Textures
glass.mojo glass.png Why transparency is sorted
floor.mojo floor.png Why mipmaps
photo.mojo photo.png A decoded PNG on a cube. The README figure.
lamps.mojo lamps.png Lights
first_scene.mojo first_scene.png Render your first scene
lit_scene.mojo lit_scene.png Light, texture and animate
rotations.mojo rotations.png Rotations
ortho.mojo cameras.png Cameras
stereo.mojo stereo.png Cameras
geometry.mojo geometry.png Geometry
instances.mojo instances.png Meshes and assets
raycast.mojo raycast.png Raycasting
curves.mojo curves.png Curves and paths
lines.mojo lines.png Lines
sprites.mojo sprites.png Points and sprites
television.mojo television.png Textures
mirror.mojo mirror.png Textures
outlines.mojo helpers.png Helpers
keyframes.mojo keyframes.png Animation
skinning.mojo skinning.png Skinning
phong.mojo phong.png Materials
physical.mojo physical.png Materials
fog.mojo fog.png Fog
culling.mojo culling.png Renderer
split.mojo split.png Renderer
clipping.mojo clipping.png Rasterization
gpu_backend.mojo gpu_backend.png GPU backend
exposure.mojo exposure.png Render target and framebuffer
model.mojo model.png Model files
orbit.mojo math.png Math
clock.mojo units.png Units
chain.mojo chain.png Why the scene graph is an array
additive.mojo additive.png Why color is linear
normals.mojo normals.png Why a normal is not a color
fragments.mojo fragments.png Why shading is per fragment
edges.mojo coverage.png Why coverage uses fixed point

photo.mojo takes the image path first: examples/photo.mojo assets/brick.png out/photo.png.

Animated outputs are APNG files. A browser or VS Code plays them. A viewer that does not know APNG shows the first frame.

Benchmarks

Program Shows
bench/raster_bench.mojo CPU against GPU rasterization across image sizes.
bench/scene_bench.mojo Each stage of the CPU renderer, one worker and every core.
tools/bench_examples.py Every example against three.js, and the Mojo 1.0 probe.

The recorded tables live on Benchmarks. The refresh command is in How to measure examples.

Tools

Program Shows
tools/gpu_status.mojo Whether an accelerator is present.
tools/doc_lint.mojo Whether the documentation follows the writing rules.

Home

Tutorials

How-to

Reference

Explanation

Clone this wiki locally