Bodies
Spheres, cylinders, cones, pyramids and the five Platonic solids each take one call. This recipe builds a white lighthouse with red rings, a glass lantern room and a copper dome, a row of garden sculptures – one for each Platonic solid, each drawn a different way – and a little topiary garden of spruce leaves.
Functions: DRAW_ELLIPSOID, DRAW_CYLINDER, DRAW_CONE, DRAW_PYRAMID and the Platonic solids DRAW_TETRAHEDRON, DRAW_OCTAHEDRON, DRAW_DODECAHEDRON and DRAW_ICOSAHEDRON, with DRAW_BOX, DRAW_BLOCK, STYLE_SOLID, STYLE_EMPTY and RENDER_CANVAS
Needs an operator
These programs call RENDER_CANVAS without input: the blocks come out of nowhere, and whatever is in the way is replaced. That only works if the owner of the trigger block is an operator, or if the server allows it with allowBlockChanges=true in config/c0de.properties; otherwise RENDER_CANVAS raises PERMISSION_DENIED. To build from a chest instead, for every player, see A first canvas.
What you need
- the mods c0de and c0de paint, and the first canvas and shapes as a start
- a trigger block with a button on it, and an empty sheet for each program
- operator rights, or
allowBlockChangeson the server (see above) - open space: about 11 × 11 blocks and 23 high for the lighthouse, a row of about 60 blocks for the sculptures
- for the exercises: a hill to dig through
The idea
A body has three parts, each with its own style, like the box of the first canvas: its edges or rims (line_style), its surface (side_style) and its inside (fill_style). A part without a style takes the style of the next part inward. So the styles you give decide what a body looks like:
| Styles | The body |
|---|---|
only fill_style | full |
only side_style | a hollow shell, the inside stays as it is |
side_style and fill_style of air | a hollow shell that clears its inside |
only line_style | a frame of edges, nothing else |
line_style and side_style | a shell with edges of a second block |
Bodies don't lie in any plane like flat shapes. They are aligned with the axes, and cylinders, cones and pyramids grow in one of six directions: "+x" (east), "-x", "+y" (up), "-y", "+z" (south) and "-z".
The lighthouse
PROGRAM lighthouse
NOOP
INCLUDE c0de/minecraft
INCLUDE c0de_paint/cpaint
NOOP
FUNCTION solid
PARAMETER id STRING
RESULT result TYPE c0de_paint/cpaint/STYLE
BEGIN
VARIABLE block STRUCT c0de_paint/cpaint/BLOCK
ASSIGN block.id id ;
CALL c0de_paint/cpaint/STYLE_SOLID
PARAMETER block block ;
RESULT result result
END FUNCTION
NOOP
FUNCTION build
PARAMETER r INTEGER 4
PARAMETER h INTEGER 16
BEGIN
VARIABLE c TYPE c0de_paint/cpaint/CANVAS
VARIABLE m STRUCT c0de_paint/cpaint/POINT
VARIABLE white TYPE c0de_paint/cpaint/STYLE
VARIABLE red TYPE c0de_paint/cpaint/STYLE
VARIABLE glass TYPE c0de_paint/cpaint/STYLE
VARIABLE copper TYPE c0de_paint/cpaint/STYLE
VARIABLE light TYPE c0de_paint/cpaint/STYLE
VARIABLE air TYPE c0de_paint/cpaint/STYLE
VARIABLE at STRUCT c0de/minecraft/POSITION
CALL solid
PARAMETER id "white_concrete" ;
RESULT result white
CALL solid
PARAMETER id "red_concrete" ;
RESULT result red
CALL solid
PARAMETER id "glass" ;
RESULT result glass
CALL solid
PARAMETER id "copper_block" ;
RESULT result copper
CALL solid
PARAMETER id "sea_lantern" ;
RESULT result light
CALL c0de_paint/cpaint/STYLE_EMPTY
RESULT result air
// the dome: half of it sinks into the lantern room
ASSIGN m.y h + 3 ;
CALL c0de_paint/cpaint/DRAW_ELLIPSOID
PARAMETER canvas c ;
PARAMETER center m ;
PARAMETER rx r - 1 ;
PARAMETER ry r - 1 ;
PARAMETER rz r - 1 ;
PARAMETER side_style copper ;
// the tower: white, with red rims, hollow
ASSIGN m.y 0 ;
CALL c0de_paint/cpaint/DRAW_CYLINDER
PARAMETER canvas c ;
PARAMETER center m ;
PARAMETER r r ;
PARAMETER h h ;
PARAMETER direction "+y" ;
PARAMETER line_style red ;
PARAMETER side_style white ;
PARAMETER fill_style air ;
// the lantern room on top, made of glass
ASSIGN m.y h ;
CALL c0de_paint/cpaint/DRAW_CYLINDER
PARAMETER canvas c ;
PARAMETER center m ;
PARAMETER r r - 1 ;
PARAMETER h 4 ;
PARAMETER direction "+y" ;
PARAMETER side_style glass ;
PARAMETER fill_style air ;
// the light in its middle
ASSIGN m.y h + 1 ;
CALL c0de_paint/cpaint/DRAW_BLOCK
PARAMETER canvas c ;
PARAMETER point m ;
PARAMETER style light ;
// the axis r + 2 blocks east of the trigger block
ASSIGN at.x PID.x + r + 2 ;
ASSIGN at.y PID.y ;
ASSIGN at.z PID.z ;
CALL c0de_paint/cpaint/RENDER_CANVAS
PARAMETER canvas c ;
PARAMETER position at ;
END FUNCTIONBuilding and running it
- Place the trigger block with the button on free ground, 2 blocks west of where the lighthouse should stand.
- Set the trigger block to
lighthouseandbuild, and press the button.
The lighthouse stands around an axis 6 blocks east of the trigger block: a tower of white concrete, 9 blocks across and 16 high, with a red ring at its foot and at its top. On it sits a lantern room of glass, 7 blocks across and 4 high, with a sea lantern in its middle, and on top a dome of copper. The whole lighthouse is 23 blocks high. Over the days, the copper turns green.

How it works
- The tower. DRAW_CYLINDER draws a disc of the radius
raroundcenterand grows it byhvoxels indirection. Its lines are the rims of both ends – the red rings. Its sides are the wall, the floor and the ceiling, in white. The fill is air: the tower is hollow inside, and whatever was there is gone. - The lantern room is a second, thinner cylinder on top of the tower, which starts at the layer
h. Its sides are glass – the floor and the roof too. - The dome. DRAW_ELLIPSOID draws a body around
centerwith three radii; equal radii make a sphere. It only has a side style, so it is a hollow shell. Its middle lies in the roof of the lantern room, so its lower half would stick into the room. - The order. That's why the dome comes first. The lantern room is drawn later and overwrites the lower half: its glass and its air are stronger, because they come last. Only the upper half of the dome remains.
- The light. DRAW_BLOCK sets the sea lantern into the air of the lantern room, one layer above its floor.
- The size.
randhhave default values. INTEGER variable itemsrandhin the trigger block make a bigger lighthouse; the lantern room and the dome grow withr.
The sculptures
The Platonic solids are the five bodies whose faces are all the same regular polygon: the tetrahedron (4 triangles), the cube (6 squares), the octahedron (8 triangles), the dodecahedron (12 pentagons) and the icosahedron (20 triangles). c0de paint has a function for each, with the corners at the distance r from center – and the cube is DRAW_BOX. This garden shows each of them in a different style.
PROGRAM sculptures
NOOP
INCLUDE c0de/minecraft
INCLUDE c0de_paint/cpaint
NOOP
FUNCTION solid
PARAMETER id STRING
RESULT result TYPE c0de_paint/cpaint/STYLE
BEGIN
VARIABLE block STRUCT c0de_paint/cpaint/BLOCK
ASSIGN block.id id ;
CALL c0de_paint/cpaint/STYLE_SOLID
PARAMETER block block ;
RESULT result result
END FUNCTION
NOOP
FUNCTION garden
PARAMETER r INTEGER 4
BEGIN
VARIABLE c TYPE c0de_paint/cpaint/CANVAS
VARIABLE m STRUCT c0de_paint/cpaint/POINT
VARIABLE a STRUCT c0de_paint/cpaint/POINT
VARIABLE b STRUCT c0de_paint/cpaint/POINT
VARIABLE gold TYPE c0de_paint/cpaint/STYLE
VARIABLE glass TYPE c0de_paint/cpaint/STYLE
VARIABLE quartz TYPE c0de_paint/cpaint/STYLE
VARIABLE moss TYPE c0de_paint/cpaint/STYLE
VARIABLE at STRUCT c0de/minecraft/POSITION
CALL solid
PARAMETER id "gold_block" ;
RESULT result gold
CALL solid
PARAMETER id "light_blue_stained_glass" ;
RESULT result glass
CALL solid
PARAMETER id "quartz_block" ;
RESULT result quartz
CALL solid
PARAMETER id "moss_block" ;
RESULT result moss
// all corners r away from the middle
ASSIGN m.y r ;
// only lines: a frame of gold
CALL c0de_paint/cpaint/DRAW_TETRAHEDRON
PARAMETER canvas c ;
PARAMETER center m ;
PARAMETER r r ;
PARAMETER line_style gold ;
// only sides: a hollow shell of glass
ASSIGN m.x 3 * r ;
CALL c0de_paint/cpaint/DRAW_OCTAHEDRON
PARAMETER canvas c ;
PARAMETER center m ;
PARAMETER r r ;
PARAMETER side_style glass ;
// the cube is a box, with lines and sides
ASSIGN a.x 5 * r + 1 ;
ASSIGN a.z 1 - r ;
ASSIGN b.x 7 * r - 1 ;
ASSIGN b.y 2 * r - 2 ;
ASSIGN b.z r - 1 ;
CALL c0de_paint/cpaint/DRAW_BOX
PARAMETER canvas c ;
PARAMETER from a ;
PARAMETER to b ;
PARAMETER line_style quartz ;
PARAMETER side_style glass ;
// only the inside: full of moss
ASSIGN m.x 9 * r ;
CALL c0de_paint/cpaint/DRAW_DODECAHEDRON
PARAMETER canvas c ;
PARAMETER center m ;
PARAMETER r r ;
PARAMETER fill_style moss ;
// lines and sides: quartz edges, glass faces
ASSIGN m.x 12 * r ;
CALL c0de_paint/cpaint/DRAW_ICOSAHEDRON
PARAMETER canvas c ;
PARAMETER center m ;
PARAMETER r r ;
PARAMETER line_style quartz ;
PARAMETER side_style glass ;
// a row from west to east, r + 2 blocks away
ASSIGN at.x PID.x + r + 2 ;
ASSIGN at.y PID.y ;
ASSIGN at.z PID.z ;
CALL c0de_paint/cpaint/RENDER_CANVAS
PARAMETER canvas c ;
PARAMETER position at ;
END FUNCTIONMove the trigger block to the west end of a free row, set it to sculptures and garden, and press the button. Five sculptures stand in a row to the east, 12 blocks apart, the first 6 blocks from the trigger block:

- DRAW_TETRAHEDRON with only a line style: a frame of gold edges. Its corners lie in alternate corners of a cube, so its lowest edge hangs a little above the ground.
- DRAW_OCTAHEDRON with only a side style: a hollow shell of glass. Its corners lie on the axes, so it stands on its lowest tip.
- The cube is a DRAW_BOX from corner to corner, 2r − 1 blocks wide, with quartz edges and glass sides.
- DRAW_DODECAHEDRON with only a fill style: the faces and the edges take it too, so it is full of moss.
- DRAW_ICOSAHEDRON with a line and a side style: 30 quartz edges and 20 glass faces.
- Small solids are rough. A voxel is a big step for a small body: below
r4, a face is only a few voxels, and the solids are hard to tell apart.r8 gives fine sculptures, in a row of 100 blocks. But a canvas ends at 255 on every axis (the settingcanvasMax): withr20, the icosahedron would reach 256, and DRAW_ICOSAHEDRON raises CANVAS_LIMIT – nothing is built.
Each solid has a fixed orientation. To turn one, you draw it into a canvas of its own and rotate it with CANVAS_ROTATE – more on that in Shaping canvases.
The topiary garden
Last, a tree and a hedge, cut into shape: a cone of leaves on a trunk, and a pyramid of leaves next to it.
PROGRAM topiary
NOOP
INCLUDE c0de/minecraft
INCLUDE c0de_paint/cpaint
NOOP
FUNCTION hedges
PARAMETER r INTEGER 3
BEGIN
VARIABLE c TYPE c0de_paint/cpaint/CANVAS
VARIABLE m STRUCT c0de_paint/cpaint/POINT
VARIABLE log STRUCT c0de_paint/cpaint/BLOCK
VARIABLE leaves STRUCT c0de_paint/cpaint/BLOCK
VARIABLE trunk TYPE c0de_paint/cpaint/STYLE
VARIABLE green TYPE c0de_paint/cpaint/STYLE
VARIABLE at STRUCT c0de/minecraft/POSITION
ASSIGN log.id "spruce_log" ;
ASSIGN leaves.id "spruce_leaves" ;
// leaves that don't fall off without a tree
ASSIGN leaves.properties["persistent"] "true" ;
CALL c0de_paint/cpaint/STYLE_SOLID
PARAMETER block log ;
RESULT result trunk
CALL c0de_paint/cpaint/STYLE_SOLID
PARAMETER block leaves ;
RESULT result green
// a tree: a trunk and a cone of leaves
CALL c0de_paint/cpaint/DRAW_CYLINDER
PARAMETER canvas c ;
PARAMETER center m ;
PARAMETER r 0 ;
PARAMETER h 2 ;
PARAMETER direction "+y" ;
PARAMETER fill_style trunk ;
ASSIGN m.y 2 ;
CALL c0de_paint/cpaint/DRAW_CONE
PARAMETER canvas c ;
PARAMETER center m ;
PARAMETER r r ;
PARAMETER h 2 * r + 1 ;
PARAMETER direction "+y" ;
PARAMETER fill_style green ;
// a hedge pyramid next to it
ASSIGN m.x 3 * r ;
ASSIGN m.y 0 ;
CALL c0de_paint/cpaint/DRAW_PYRAMID
PARAMETER canvas c ;
PARAMETER center m ;
PARAMETER r r ;
PARAMETER h r ;
PARAMETER direction "+y" ;
PARAMETER fill_style green ;
ASSIGN at.x PID.x + r + 2 ;
ASSIGN at.y PID.y ;
ASSIGN at.z PID.z ;
CALL c0de_paint/cpaint/RENDER_CANVAS
PARAMETER canvas c ;
PARAMETER position at ;
END FUNCTIONSet the trigger block to topiary and hedges and press the button. A spruce tree, 10 blocks high, grows 5 blocks east of the trigger block, and a pyramid hedge of 7 × 7 blocks and 4 high stands 14 blocks east of it.
- The trunk is a cylinder with the radius 0: a single column of spruce logs, 2 high.
- The crown. DRAW_CONE draws a cone on the base of a cylinder; its tip lies
hvoxels from the base indirection. Withr3 andh7, it is a slim tree. - The hedge. DRAW_PYRAMID has a square base whose sides are 2r + 1 voxels long, and its tip lies
hvoxels above. - Leaves that stay. Leaves without a tree nearby decay in Minecraft. The block state
persistent"true" makes them stay, like leaves a player places. The BLOCK of the leaves gets it in itsproperties, sosolidisn't enough here.
Try it yourself
- The lighthouse has no door. Cut one into its west wall, facing the trigger block: 1 block wide and 2 high, above the floor.
Solution
A DRAW_BOX of air from - r,1,0 to - r,2,0, drawn after the tower, overwrites the white concrete there. In the middle row, the wall is only one block thick.
PROGRAM lighthousedoor
NOOP
INCLUDE c0de/minecraft
INCLUDE c0de_paint/cpaint
NOOP
FUNCTION solid
PARAMETER id STRING
RESULT result TYPE c0de_paint/cpaint/STYLE
BEGIN
VARIABLE block STRUCT c0de_paint/cpaint/BLOCK
ASSIGN block.id id ;
CALL c0de_paint/cpaint/STYLE_SOLID
PARAMETER block block ;
RESULT result result
END FUNCTION
NOOP
FUNCTION build
PARAMETER r INTEGER 4
PARAMETER h INTEGER 16
BEGIN
VARIABLE c TYPE c0de_paint/cpaint/CANVAS
VARIABLE m STRUCT c0de_paint/cpaint/POINT
VARIABLE d STRUCT c0de_paint/cpaint/POINT
VARIABLE white TYPE c0de_paint/cpaint/STYLE
VARIABLE red TYPE c0de_paint/cpaint/STYLE
VARIABLE glass TYPE c0de_paint/cpaint/STYLE
VARIABLE copper TYPE c0de_paint/cpaint/STYLE
VARIABLE light TYPE c0de_paint/cpaint/STYLE
VARIABLE air TYPE c0de_paint/cpaint/STYLE
VARIABLE at STRUCT c0de/minecraft/POSITION
CALL solid
PARAMETER id "white_concrete" ;
RESULT result white
CALL solid
PARAMETER id "red_concrete" ;
RESULT result red
CALL solid
PARAMETER id "glass" ;
RESULT result glass
CALL solid
PARAMETER id "copper_block" ;
RESULT result copper
CALL solid
PARAMETER id "sea_lantern" ;
RESULT result light
CALL c0de_paint/cpaint/STYLE_EMPTY
RESULT result air
// the dome: half of it sinks into the lantern room
ASSIGN m.y h + 3 ;
CALL c0de_paint/cpaint/DRAW_ELLIPSOID
PARAMETER canvas c ;
PARAMETER center m ;
PARAMETER rx r - 1 ;
PARAMETER ry r - 1 ;
PARAMETER rz r - 1 ;
PARAMETER side_style copper ;
// the tower: white, with red rims, hollow
ASSIGN m.y 0 ;
CALL c0de_paint/cpaint/DRAW_CYLINDER
PARAMETER canvas c ;
PARAMETER center m ;
PARAMETER r r ;
PARAMETER h h ;
PARAMETER direction "+y" ;
PARAMETER line_style red ;
PARAMETER side_style white ;
PARAMETER fill_style air ;
// the lantern room on top, made of glass
ASSIGN m.y h ;
CALL c0de_paint/cpaint/DRAW_CYLINDER
PARAMETER canvas c ;
PARAMETER center m ;
PARAMETER r r - 1 ;
PARAMETER h 4 ;
PARAMETER direction "+y" ;
PARAMETER side_style glass ;
PARAMETER fill_style air ;
// the light in its middle
ASSIGN m.y h + 1 ;
CALL c0de_paint/cpaint/DRAW_BLOCK
PARAMETER canvas c ;
PARAMETER point m ;
PARAMETER style light ;
// the door: 2 blocks of air in the west wall
ASSIGN m.x - r ;
ASSIGN m.y 1 ;
ASSIGN d.x - r ;
ASSIGN d.y 2 ;
CALL c0de_paint/cpaint/DRAW_BOX
PARAMETER canvas c ;
PARAMETER from m ;
PARAMETER to d ;
PARAMETER fill_style air ;
// the axis r + 2 blocks east of the trigger block
ASSIGN at.x PID.x + r + 2 ;
ASSIGN at.y PID.y ;
ASSIGN at.z PID.z ;
CALL c0de_paint/cpaint/RENDER_CANVAS
PARAMETER canvas c ;
PARAMETER position at ;
END FUNCTION- Dig a tunnel through a hill: a round tube of stone bricks, 7 blocks across and 12 long, that runs east, starting 2 blocks east of the trigger block.
Solution
A cylinder lying on its side, with direction "+x". But the sides of a cylinder include its two ends, so the tube would be closed. A second, thinner cylinder of air, as long as the first one, clears the inside and opens both ends. The axis lies 2 above the trigger block, so the floor of the tunnel is 1 block below it.
PROGRAM tunnel
NOOP
INCLUDE c0de/minecraft
INCLUDE c0de_paint/cpaint
NOOP
FUNCTION solid
PARAMETER id STRING
RESULT result TYPE c0de_paint/cpaint/STYLE
BEGIN
VARIABLE block STRUCT c0de_paint/cpaint/BLOCK
ASSIGN block.id id ;
CALL c0de_paint/cpaint/STYLE_SOLID
PARAMETER block block ;
RESULT result result
END FUNCTION
NOOP
FUNCTION tunnel
PARAMETER r INTEGER 3
PARAMETER length INTEGER 12
BEGIN
VARIABLE c TYPE c0de_paint/cpaint/CANVAS
VARIABLE m STRUCT c0de_paint/cpaint/POINT
VARIABLE walls TYPE c0de_paint/cpaint/STYLE
VARIABLE air TYPE c0de_paint/cpaint/STYLE
VARIABLE at STRUCT c0de/minecraft/POSITION
CALL solid
PARAMETER id "stone_bricks" ;
RESULT result walls
CALL c0de_paint/cpaint/STYLE_EMPTY
RESULT result air
// a lying cylinder, its floor 1 below the trigger block
ASSIGN m.y r - 1 ;
CALL c0de_paint/cpaint/DRAW_CYLINDER
PARAMETER canvas c ;
PARAMETER center m ;
PARAMETER r r ;
PARAMETER h length ;
PARAMETER direction "+x" ;
PARAMETER side_style walls ;
// its ends are sides too: a thinner one of air
CALL c0de_paint/cpaint/DRAW_CYLINDER
PARAMETER canvas c ;
PARAMETER center m ;
PARAMETER r r - 1 ;
PARAMETER h length ;
PARAMETER direction "+x" ;
PARAMETER fill_style air ;
ASSIGN at.x PID.x + 2 ;
ASSIGN at.y PID.y ;
ASSIGN at.z PID.z ;
CALL c0de_paint/cpaint/RENDER_CANVAS
PARAMETER canvas c ;
PARAMETER position at ;
END FUNCTION- Give the lighthouse a flatter dome.
Solution
Change one line: the radius ry of DRAW_ELLIPSOID is the height of the dome. With PARAMETER ry 2 ; instead of r - 1, the dome is lower than it is wide. The radii rx and rz stay, so it still fits on the lantern room.
Read more
- The functions of this recipe: DRAW_ELLIPSOID, DRAW_CYLINDER, DRAW_CONE, DRAW_PYRAMID, the Platonic solids and DRAW_BOX
- Shapes in any plane: windows, arches and a spiral staircase
- Styles: stripes, gradients and random blocks instead of plain white
- Shaping canvases: rotating, mirroring and scaling bodies
- Owner and permissions in the guide