Rainbow reef¶
Sample a gyroid surface inside a sphere, give it a dark core, and color its outer shell with a rainbow. The open channels expose the core behind the colors; a blackstone plinth supports the clipped lower edge.
With uv installed, download reef.py and run:
uv run --with mcschemora reef.py
The script writes output/reef.schem and a 1600 × 1600 output/reef.png.
The default sphere is 64 blocks across with 2.5 surface repetitions and thickness
0.35. Edit the downloaded file to change its geometry or colors.
Geometry¶
placements() yields (position, block) pairs, starting with two layers of
polished blackstone and a narrower black-concrete deck:
def placements():
for y, margin, material in ((0, 3, foundation), (1, 3, foundation), (2, 2, dark)):
for x in range(-margin, diameter + margin):
for z in range(-margin, diameter + margin):
yield (x, y, z), material
At diameter 64, the blackstone extends from -3 through 66 on X and Z. The margin
shrinks the top layer by one block on each side.

Above the plinth, a gyroid forms a repeating surface with channels passing through
it. The script evaluates this field using scaled coordinates u, v, and w:
sin(u) × cos(w) + sin(v) × cos(u) + sin(w) × cos(v)
Positions close enough to zero belong to the surface. The thickness threshold
controls that band: lower values leave thinner walls and wider channels.
To fit periods repetitions across the diameter, the generator centers and scales
the sampling grid. Each coordinate's square, sine, and cosine are calculated
once for reuse in the inner loops:
center = (diameter - 1) / 2
radius = diameter / 2
radius_squared = radius * radius
interior_radius_squared = (radius * 0.8) ** 2
scale = tau * periods / diameter
samples = tuple(
(
(coordinate - center) ** 2,
sin((coordinate - center) * scale),
cos((coordinate - center) * scale),
)
for coordinate in range(diameter)
)
The loops clip the field to a sphere by comparing squared distance from the
center with radius_squared, skipping positions outside it. Cutting off the
lower part lets the reef sit on its plinth.

White concrete in place of the exterior colors makes the channels easier to inspect before choosing a palette.
Color¶
atan2 gives the angle around the vertical axis. A height-dependent twist
shifts the palette as the surface rises, and modulo wraps the result into a
single cycle before conversion to a palette index:
interior_remaining = interior_radius_squared - x_squared - z_squared
angle = atan2(z - center, x - center) / tau
term = sx * cz
for y in range(bottom, diameter):
y_squared, sy, cy = samples[y]
if y_squared <= remaining and abs(term + sy * cx + sz * cy) < thickness:
index = int(((angle + twists[y]) % 1) * len(palette))
material = dark if y_squared <= interior_remaining else palette[index]
yield (x, y - bottom + 3, z), material
Cells within 80% of the sphere's radius use black concrete. The palette colors
the remaining shell, leaving dark channels behind it. Edit COLORS at the top
of the downloaded file to use another set of concrete colors.
After yielding the base and surface, the generator writes all placements in one batch:
schematic.region().set_many(placements())
return schematic
The entry point saves the schematic and calls export_png. See
building for more on batches and palettes.
Change the shape¶
Try a smaller reef with thinner walls, saving it separately:
uv run --with mcschemora reef.py --diameter 48 --periods 2 --thickness 0.25 --output small-reef
| Option | What changes | Accepted values |
|---|---|---|
--diameter |
Sphere size in blocks. | 16 through 128 |
--periods |
Surface repetitions across the diameter. | 1 through diameter / 8 |
--thickness |
Width of the solid band around the surface. | Greater than 0 and less than 1 |
Read the complete script
import argparse
from math import atan2, cos, sin, tau
from pathlib import Path
from mcschemora import Schematic, block
COLORS = (
"purple",
"blue",
"light_blue",
"cyan",
"green",
"lime",
"yellow",
"orange",
"red",
"magenta",
)
def create_reef(diameter=64, periods=2.5, thickness=0.35):
if not 16 <= diameter <= 128:
raise ValueError("Diameter must be between 16 and 128 blocks.")
if not 1 <= periods <= diameter / 8:
raise ValueError("Periods must be between 1 and diameter / 8.")
if not 0 < thickness < 1:
raise ValueError("Thickness must be between 0 and 1, exclusive.")
schematic = Schematic.create(version="1.21.1")
palette = tuple(block(f"{color}_concrete") for color in COLORS)
foundation = block("polished_blackstone")
dark = block("black_concrete")
center = (diameter - 1) / 2
radius = diameter / 2
radius_squared = radius * radius
interior_radius_squared = (radius * 0.8) ** 2
scale = tau * periods / diameter
samples = tuple(
(
(coordinate - center) ** 2,
sin((coordinate - center) * scale),
cos((coordinate - center) * scale),
)
for coordinate in range(diameter)
)
bottom = diameter // 8
twists = tuple(0.9 * (y - center) / diameter for y in range(diameter))
def placements():
for y, margin, material in ((0, 3, foundation), (1, 3, foundation), (2, 2, dark)):
for x in range(-margin, diameter + margin):
for z in range(-margin, diameter + margin):
yield (x, y, z), material
for x, (x_squared, sx, cx) in enumerate(samples):
for z, (z_squared, sz, cz) in enumerate(samples):
remaining = radius_squared - x_squared - z_squared
if remaining < 0:
continue
interior_remaining = interior_radius_squared - x_squared - z_squared
angle = atan2(z - center, x - center) / tau
term = sx * cz
for y in range(bottom, diameter):
y_squared, sy, cy = samples[y]
if y_squared <= remaining and abs(term + sy * cx + sz * cy) < thickness:
index = int(((angle + twists[y]) % 1) * len(palette))
material = dark if y_squared <= interior_remaining else palette[index]
yield (x, y - bottom + 3, z), material
schematic.region().set_many(placements())
return schematic
def main():
parser = argparse.ArgumentParser(description="Build and render a rainbow gyroid reef.")
parser.add_argument("--output", type=Path, default=Path("output"))
parser.add_argument("--diameter", type=int, default=64)
parser.add_argument("--periods", type=float, default=2.5)
parser.add_argument("--thickness", type=float, default=0.35)
args = parser.parse_args()
try:
schematic = create_reef(args.diameter, args.periods, args.thickness)
except ValueError as error:
parser.error(str(error))
args.output.mkdir(parents=True, exist_ok=True)
schematic.save(args.output / "reef.schem")
image_path = args.output / "reef.png"
diagnostics = schematic.export_png(image_path, size=(1600, 1600))
print(f"Saved reef.schem and reef.png ({image_path.stat().st_size / 1024:.0f} KiB)")
for diagnostic in diagnostics:
print(diagnostic)
if __name__ == "__main__":
main()
