All puzzles › Computer Graphics
Computer Graphics Practice Problems
28 puzzles (7 easy, 13 medium, 8 hard), 8 free, in Python, JavaScript and C++.
Rasterization, ray tracing, shading and colour: the math that turns numbers into pictures.
The puzzles, easiest first
- Shades From Black and White (Easy, free): A screen that can only show black or white can still fake gray, by lighting some pixels and not others.
- Which Eighth of the Box (Easy, free): An octree splits a box of space into eight smaller boxes around its center, and to store a point you need to know which of the eight it falls in.
- AABB Overlap Test (Easy): Given two boxes as [x1, y1, x2, y2], return true if they overlap.
- Alpha Blending (Easy): Given a new color, the color behind it, and an alpha from 0 to 1, return the blended color, rounded to 4 decimals.
- Colour Gradient Lerp (Easy): Given two colors a and b and a fraction t from 0 to 1, return the color t of the way from a to b, rounded to 4 decimals.
- Gamma Correction (Easy): Given a list of color values from 0 to 1, raise each one to the power 1 / 2.2 and return the results, rounded to 4 decimals.
- Relative Luminance (Easy): Given a color as [r, g, b], each from 0 to 1, return its brightness, rounded to 4 decimals: 0.2126 x r + 0.7152 x g + 0.0722 x b.
- Any Rectangle in Four Lookups (Medium, free): Adding up the pixels in a rectangle normally means visiting every one.
- Pass the Error Along (Medium, free): Turning gray into black and white always gets each pixel a little wrong.
- Read the Contour From the Corners (Medium, free): To draw a contour line through a grid of measurements, look at each small square formed by four neighboring values.
- Step by the Safe Distance (Medium, free): A ray starts at x = 0 and travels right along the x axis.
- Backface Culling (Medium): Given a triangle's three corners on screen, return true if it faces you.
- Barycentric Coordinates (Medium): Given a triangle's three corners a, b, and c and a point p, return p's barycentric weights [w0, w1, w2], rounded to 4 decimals.
- Bilinear Texture Filter (Medium): Given a 2 by 2 grid of texture values and a point (u, v), each from 0 to 1, return the blended value, rounded to 4 decimals.
- Bresenham's Line (Medium): Given two points, return every pixel on the line between them, start to end.
- Perlin's Fade Curve (Medium): Given t from 0 to 1, return 6t^5 - 15t^4 + 10t^3, rounded to 4 decimals.
- Reinhard Tone Mapping (Medium): Given a list of brightness values that can be any size, squash each one into the range 0 to 1 with c / (1 + c), rounded to 4 decimals.
- The Perspective Divide (Medium): Given a point in clip space as [x, y, z, w], return [x / w, y / w, z / w], rounded to 4 decimals.
- Viewport Transform (Medium): Given a point from -1 to 1 on each axis, plus a screen width and height, return its pixel position, rounded to 2 decimals.
- Z-Buffer Depth Test (Medium): Given a depth grid and a list of fragments as [x, y, z], return the grid after testing every fragment.
- A Curve That Never Jumps (Hard, free): A Hilbert curve visits every cell of a 2^order by 2^order grid exactly once, and each step moves to a touching cell.
- Which Pixels Are Inside (Hard, free): A GPU decides which pixels a triangle covers by testing each pixel's center against the three edges.
- De Casteljau's Algorithm (Hard): Given four control points and t from 0 to 1, return the point on the Bezier curve at t, rounded to 4 decimals.
- Gaussian Splat Compositing (Hard): Given each splat's alpha and color, front to back, return the final color, rounded to 4 decimals.
- Morton Code (Z-Order) (Hard): Given x and y, return their Morton code by interleaving their bits: x's bits go in the even positions and y's bits go in the odd ones.
- Ray-Box Slab Test (Hard): Given a ray's origin and direction and a box's min and max corners, return true if the ray hits the box.
- Ray-Sphere Intersection (Hard): Given a ray's origin o and unit direction d, and a sphere's center c and radius r, return the distance t to the nearest hit in front of the ray, rounded to 4 decimals, or -1 for a miss.
- Schlick's Fresnel (Hard): Given a base reflectance f0 as [r, g, b] and the cosine of the viewing angle, return the reflectance for each channel, rounded to 4 decimals: f0 + (1 - f0) x (1 - cos)^5.
Practice another pattern
Or browse by subject
Browse all 676 puzzles