c0de_paint/cpaint
c0de paint adds the libraries c0de_paint/cpaint and c0de_paint/schematics to c0de. Programs draw lines, flat shapes and bodies into canvases, combine and transform them, read schematics of Litematica and Create, and build them in the world. Every program has the constant C0DE_PAINT_VERSION with the version of c0de paint as text, like "0.2.0". This handbook describes the types, the styles, the drawing functions, the canvas operations, rendering, the errors and the settings, with examples.
Chapters
- Getting started: Programs that use the library include it with INCLUDE c0de_paint/cpaint. Its types and functions start with the library name, like …
- Errors: The libraries raise the errors of c0de where they fit and errors of their own, which are constants of the libraries, like c0de_paint/cpaint/CANVAS_LIMIT and …
- Examples: A round tower of stone bricks with a cone of dark oak planks on top.
Types
- CANVAS: A canvas is a three-dimensional grid of voxels without a fixed size; it grows with its content. Every voxel is either not set or holds a block. Air is a …
- STYLE: A style says how a part of a shape is drawn: not at all, with air, with one block, with random blocks, with a gradient or with a pattern. Styles are made …
- POINT: A voxel of a canvas: the elements x, y and z, all INTEGER. Positions in the world are POSITIONs of c0de/minecraft.
- BLOCK: A block of a style or of a canvas: id STRING, properties HASH STRING with block states as in PLACE_BLOCK, weight INTEGER and data STRING. An id without a …
Styles
- STYLE_NONE: Don't draw: the voxels stay as they are.
- STYLE_EMPTY: Air: erases voxels that were drawn before. Drawn into a full body, it makes hollow bodies with thick walls.
- STYLE_SOLID: Always the same block. Its weight doesn't matter.
- STYLE_RANDOM: For every voxel a randomly chosen block. The chance of a block is its weight divided by the sum of all weights. The random numbers come from the process, …
- STYLE_GRADIENT: A gradient through the blocks in their order. The first block is drawn at from. The distance from from is measured along axes: "xyz" gives spheres, "y" …
- STYLE_PATTERN: Repeats a canvas along all three axes. One repetition has the size of the bounds of the pattern, and its minimum corner lies at from. Voxels that are not …
- INVENTORY_BLOCKS: The blocks of an inventory, for STYLE_RANDOM and STYLE_GRADIENT: in the order of the slots, with the number of items as weight. A block in several slots is …
Drawing
- DRAW_BLOCK: Draws one voxel.
- DRAW_LINE: Draws a straight line between two points.
- DRAW_RECTANGLE: Draws a rectangle. a and b are the ends of one side; the other side runs perpendicular to it, up to the distance of c from the line through a and b. With a …
- DRAW_POLYGON: Draws a polygon through the points, closed automatically. The first three points that don't lie on one line define the plane; points beside it are projected …
- DRAW_ELLIPSE: Draws an ellipse around center. The distance of a from the center is the first semi-axis. b lies in the plane of the ellipse; its distance from the first …
- DRAW_ARC: Draws the part of the ellipse of DRAW_ELLIPSE from the angle start to end, in degrees, counted from a towards b. The line is the arc; the fill style draws a …
- DRAW_SPIRAL: Draws a spiral on the ellipse of DRAW_ELLIPSE that rises in direction. It starts at a and turns towards b. Every voxel of the spiral lies elevation layers …
- DRAW_BOX: Draws an axis-aligned box between two opposite corners. The lines are its 12 edges. A cube is a box with equal sides.
- DRAW_ELLIPSOID: Draws an axis-aligned ellipsoid with the radii rx, ry and rz; a sphere when they are equal. A radius of 0 makes it flat on that axis.
- DRAW_CYLINDER: Draws a cylinder. The base circle has its center at center and the radius r; the cylinder grows by h voxels in direction. The lines are the rims of both …
- DRAW_CONE: Draws a cone with the base of DRAW_CYLINDER; its tip lies h voxels from the base in direction. The line is the rim of the base.
- DRAW_PYRAMID: Draws a pyramid with a square base, its sides parallel to the axes. Half the length of a side is r; the tip lies h voxels from the base in direction. The …
- Platonic solids: DRAW_TETRAHEDRON, DRAW_OCTAHEDRON, DRAW_DODECAHEDRON and DRAW_ICOSAHEDRON draw the Platonic solid around center, with all corners at the distance r from it. …
Canvas operations
- CANVAS_COUNT: The number of set voxels.
- CANVAS_MIN and CANVAS_MAX: The corners of the bounds. An empty canvas raises CANVAS_EMPTY.
- CANVAS_GET: The block of a voxel, with the weight 1. Its id is "" if the voxel is not set, and "minecraft:air" for air.
- CANVAS_CLEAR and CANVAS_CROP: CANVAS_CLEAR unsets the voxels in the box from from to to, or all voxels without them. CANVAS_CROP unsets all voxels outside the box.
- CANVAS_MOVE: Moves the content by offset.
- CANVAS_REPLACE: Draws every voxel with the block id again with style, whatever the states of the block are. The new block keeps the states of the old one that it also has, …
- CANVAS_MERGE: Draws source, a canvas or an ARRAY of canvases, into target, moved by offset. With mode "OVERWRITE", set voxels of the source replace those of the target; …
- CANVAS_MATERIALS: The blocks of a canvas, as a HASH from block id to number, without air (CANVAS_COUNT counts air). Blocks with different states count together. CANVAS_ITEMS …
- CANVAS_ITEMS: The items that RENDER_CANVAS takes to build the canvas, as a HASH from item id to number: two slabs for a double slab, three candles for a block of three …
- CANVAS_SCALE: Scales the canvas around center along every axis by a percentage of 1 or more. Every voxel takes the nearest voxel of the original, so blocks keep their states.
- CANVAS_ROTATE: Rotates the canvas around the axis "x", "y" or "z" through center by any angle in degrees. Positive angles follow the right-hand rule: +90 about y turns …
- CANVAS_MIRROR: Mirrors the canvas at the plane perpendicular to the axis at position, like 4.5 for the plane between the voxels 4 and 5. Without position, it mirrors at …
Rendering
- RENDER_CANVAS: Builds the canvas in the world; its voxel 0,0,0 lands at position. Voxels that are not set leave the world as it is, air removes the block there, and blocks …
- CANVAS_FROM_WORLD: A new canvas with the blocks of the world between two positions, with their states and their data (the contents of chests, the text of signs); from becomes …
Canvas files
- The file format: The files are YAML, text that you can read and change in an editor:
- SAVE_CANVAS: Writes the canvas into a file. A file that exists is only replaced with overwrite TRUE, otherwise SCHEMATIC_EXISTS. The client of the player must allow …
- LOAD_CANVAS: Reads a canvas from a file. A file that isn't a canvas file raises SCHEMATIC_INVALID, with the row or entry that is wrong in the message; a voxel outside …