The grapics libaray provides functions to create a scene with 3D geometric shapes. Works together with
the pacioli.js library to display a 3D geometric space in the browser. Depends on the
geometry library.
The following example creates a scene with 8 arrows pointing in various directions from the origin.
The parameters a, b and c get passed at runtime.
import geometry;
define my_scene(a, b, c) =
let scene = empty_scene("My nice scene!") in
add_arrows(my_arrows(a, b, c), scene)
end;
define my_arrows(a, b, c) =
[origin_arrow(vec, "blue") | i <- [-1, 1],
j <- [-1, 1],
k <- [-1, 1],
vec := vector3d(i*a*|metre|, j*b*|metre|, k*c*|metre|)];
After compilation the function my_scene can be used to connect the scene to a web component or it can be called directly
from javascript code to create the scene at runtime. See the pacioli.js library for the runtime API.
The library also provides some elementary animation.
add_animation_callback :: for_unit a, Geom3!u: ((second, Scene(a, Geom3!u)) -> Scene(a, Geom3!u), Scene(a, Geom3!u)) -> Animation(a, Geom3!u) add_arrows :: for_unit a, Geom3!u: (List(Arrow(a, Geom3!u)), Scene(a, Geom3!u)) -> Scene(a, Geom3!u) add_labels :: for_unit a, Geom3!u: (List(Label(a, Geom3!u)), Scene(a, Geom3!u)) -> Scene(a, Geom3!u) add_meshes :: for_unit a, Geom3!u: (List(Mesh(a, Geom3!u)), Scene(a, Geom3!u)) -> Scene(a, Geom3!u) add_paths :: for_unit a, Geom3!u: (List(Path(a, Geom3!u)), Scene(a, Geom3!u)) -> Scene(a, Geom3!u) add_spotlights :: for_unit a, Geom3!u: (List(SpotLight(a, Geom3!u)), Scene(a, Geom3!u)) -> Scene(a, Geom3!u) add_stateful_animation_callback :: for_type t: for_unit a, Geom3!u: (t, (second, t, Scene(a, Geom3!u)) -> Tuple(t, Scene(a, Geom3!u)), Scene(a, Geom3!u)) -> StatefulAnimation(a, Geom3!u, t) arrow_color :: for_unit a, Geom3!u: (Arrow(a, Geom3!u)) -> Color arrow_label :: for_unit a, Geom3!u: (Arrow(a, Geom3!u)) -> String arrow_name :: for_unit a, Geom3!u: (Arrow(a, Geom3!u)) -> String color_string :: (Color) -> String cube_mesh :: for_unit a: (a, Color) -> Mesh(a, Geom3!) default_arrow :: for_unit a, Geom3!u: (a*Geom3!u, a*Geom3!u) -> Arrow(a, Geom3!u) default_label :: for_unit a, Geom3!b: (String, a*Geom3!b) -> Label(a, Geom3!b) default_line :: for_unit a, Geom3!u: (a*Geom3!u, a*Geom3!u) -> Path(a, Geom3!u) default_mesh :: for_unit a, Geom3!u: (List(Vertex(a, Geom3!u)), List(Face)) -> Mesh(a, Geom3!u) default_path :: for_unit a, Geom3!u: (List(a*Geom3!u)) -> Path(a, Geom3!u) empty_scene :: for_unit a, Geom3!u: (String) -> Scene(a, Geom3!u) face :: (1, 1, 1) -> Face make_arrow :: for_unit a, Geom3!u: (a*Geom3!u, a*Geom3!u, String, String, Color) -> Arrow(a, Geom3!u) make_color :: (String) -> Color make_label :: for_unit a, Geom3!u: (String, a*Geom3!u, Color, String, 1) -> Label(a, Geom3!u) make_line :: for_unit a, Geom3!u: (a*Geom3!u, a*Geom3!u, Color) -> Path(a, Geom3!u) make_mesh :: for_unit a, Geom3!u: (List(Vertex(a, Geom3!u)), List(Face), Maybe(a*Geom3!u), Tuple(radian, radian, radian), String, Boole, String) -> Mesh(a, Geom3!u) make_path :: for_unit a, Geom3!u: (List(a*Geom3!u), Color) -> Path(a, Geom3!u) make_spotlight :: for_unit a, Geom3!u: (a*Geom3!u, a*Geom3!u, Color, candela) -> SpotLight(a, Geom3!u) make_text :: for_unit a, Geom3!u: (String, a*Geom3!u, a*Geom3!u, Color, String) -> Text(a, Geom3!u) move_arrow :: for_unit a, Geom3!u: (Arrow(a, Geom3!u), a*Geom3!u, a*Geom3!u) -> Arrow(a, Geom3!u) move_mesh :: for_unit a, Geom3!u: (Mesh(a, Geom3!u), a*Geom3!u) -> Mesh(a, Geom3!u) named_cube_mesh :: for_unit a: (String, a, Color) -> Mesh(a, Geom3!) named_mesh :: for_unit a, Geom3!u: (List(Vertex(a, Geom3!u)), List(Face), String) -> Mesh(a, Geom3!u) origin_arrow :: for_unit a, Geom3!u: (a*Geom3!u) -> Arrow(a, Geom3!u) rgb :: (1, 1, 1) -> Color rotate_mesh :: for_unit a, Geom3!u: (Mesh(a, Geom3!u), radian, radian, radian) -> Mesh(a, Geom3!u) scene_arrows :: for_unit a, Geom3!u: (Scene(a, Geom3!u)) -> List(Arrow(a, Geom3!u)) scene_meshes :: for_unit a, Geom3!u: (Scene(a, Geom3!u)) -> List(Mesh(a, Geom3!u)) scene_paths :: for_unit a, Geom3!u: (Scene(a, Geom3!u)) -> List(Path(a, Geom3!u)) set_wireframe :: for_unit a, Geom3!u: (Mesh(a, Geom3!u), Boole) -> Mesh(a, Geom3!u) vertex :: for_unit a, Geom3!u: (a*Geom3!u, Color) -> Vertex(a, Geom3!u) with_ambient_light :: for_unit a, Geom3!u: (String, 1, Scene(a, Geom3!u)) -> Scene(a, Geom3!u) with_arrow_color :: for_unit a, Geom3!u: (Color, Arrow(a, Geom3!u)) -> Arrow(a, Geom3!u) with_arrow_label :: for_unit a, Geom3!u: (String, Arrow(a, Geom3!u)) -> Arrow(a, Geom3!u) with_arrow_name :: for_unit a, Geom3!u: (String, Arrow(a, Geom3!u)) -> Arrow(a, Geom3!u) with_mesh_material :: for_unit a, Geom3!u: (String, Mesh(a, Geom3!u)) -> Mesh(a, Geom3!u) with_mesh_name :: for_unit a, Geom3!u: (String, Mesh(a, Geom3!u)) -> Mesh(a, Geom3!u) with_mesh_wireframe :: for_unit a, Geom3!u: (Boole, Mesh(a, Geom3!u)) -> Mesh(a, Geom3!u) with_path_color :: for_unit a, Geom3!u: (Color, Path(a, Geom3!u)) -> Path(a, Geom3!u) with_scene_arrows :: for_unit a, Geom3!u: (List(Arrow(a, Geom3!u)), Scene(a, Geom3!u)) -> Scene(a, Geom3!u) with_scene_meshes :: for_unit a, Geom3!u: (List(Mesh(a, Geom3!u)), Scene(a, Geom3!u)) -> Scene(a, Geom3!u) with_scene_paths :: for_unit a, Geom3!u: (List(Path(a, Geom3!u)), Scene(a, Geom3!u)) -> Scene(a, Geom3!u)
for_unit a, Geom3!u: Arrow(a, Geom3!u)
An arrow is a colored line segment from from one position to another, with an arrowhead at the end.
Is an element of a scene.
for_unit a, Geom3!u: Path(a, Geom3!u)
A series of lines between succesive points. Is an element of a
Scene(a, Geom3!u) scene.
for_unit a, Geom3!u: Vertex(a, Geom3!u)
A point in a Mesh(a, Geom3!u) mesh.
Color
The color of a graphics element.
Uses the html color format. For example "#ffffff" and "white" both represent the color white
for_unit a, Geom3!u: Label(a, Geom3!u)
for_unit a, Geom3!u: Animation(a, Geom3!u)
Combines a Scene with an animation callback.
for_unit a, Geom3!u: Mesh(a, Geom3!u)
A 3D shape composed from faces and vertices. Is an element of a
Scene(a, Geom3!u) scene.
for_unit a, Geom3!u: Text(a, Geom3!u)
A spotlight. Is an element of a Scene(a, Geom3!u) scene.
for_unit a, Geom3!u: Scene(a, Geom3!u)
A scene is a geometric space that can contain vectors, meshes and paths. It
is a space with vectors of type a*Geom3!u.
Currently it can only be displayed in a browser.
Face
A suface between a mesh's vertices.
for_unit a, Geom3!u: SpotLight(a, Geom3!u)
A spotlight. Is an element of a Scene(a, Geom3!u) scene.
for_type t: for_unit a, Geom3!u: StatefulAnimation(a, Geom3!u, t)
Combines a Scene with an animation callback that accepts a state parameter.
:: for_unit a, Geom3!u: ((second, Scene(a, Geom3!u)) -> Scene(a, Geom3!u), Scene(a, Geom3!u)) -> Animation(a, Geom3!u)
Adds an animation callback to the scene. The function is called during animation with the current frame number and the current named scene.
The function must return a scene with the same element names. The existing scene elements then get updated with the properties from the returned elements.
The scene is filtered for named elements.
:: for_unit a, Geom3!u: (List(Arrow(a, Geom3!u)), Scene(a, Geom3!u)) -> Scene(a, Geom3!u)
Adds arrows to a scene
:: for_unit a, Geom3!u: (List(Label(a, Geom3!u)), Scene(a, Geom3!u)) -> Scene(a, Geom3!u)
Adds labels to a scene
:: for_unit a, Geom3!u: (List(Mesh(a, Geom3!u)), Scene(a, Geom3!u)) -> Scene(a, Geom3!u)
Adds meshes to a scene
:: for_unit a, Geom3!u: (List(Path(a, Geom3!u)), Scene(a, Geom3!u)) -> Scene(a, Geom3!u)
Adds paths to a scene
:: for_unit a, Geom3!u: (List(SpotLight(a, Geom3!u)), Scene(a, Geom3!u)) -> Scene(a, Geom3!u)
Adds spotlights to a scene
:: for_type t: for_unit a, Geom3!u: (t, (second, t, Scene(a, Geom3!u)) -> Tuple(t, Scene(a, Geom3!u)), Scene(a, Geom3!u)) -> StatefulAnimation(a, Geom3!u, t)
Adds an animation callback to the scene. The function is called during animation with the current frame number, the current state and the current scene. In the first call the initial value is passed to the callback.
The function must return a tuple of the new state and scene with the same element names as the elements in the passed scene. The existing scene elements then get updated with the properties from the returned elements.
The scene is filtered for named elements.
:: for_unit a, Geom3!u: (Arrow(a, Geom3!u)) -> Color
Getter for record Arrow(a, Geom3!u)
:: for_unit a, Geom3!u: (Arrow(a, Geom3!u)) -> String
Getter for record Arrow(a, Geom3!u)
:: for_unit a, Geom3!u: (Arrow(a, Geom3!u)) -> String
Getter for record Arrow(a, Geom3!u)
:: (Color) -> String
The html string representation of the color.
:: for_unit a: (a, Color) -> Mesh(a, Geom3!)
Creates a cube mesh, a mesh with lengths of 'size' positioned at the origin.
:: for_unit a, Geom3!u: (a*Geom3!u, a*Geom3!u) -> Arrow(a, Geom3!u)
Creates an arrow between two points.
:: for_unit a, Geom3!b: (String, a*Geom3!b) -> Label(a, Geom3!b)
:: for_unit a, Geom3!u: (a*Geom3!u, a*Geom3!u) -> Path(a, Geom3!u)
A line between two points. Each point is indicated by a vector.
:: for_unit a, Geom3!u: (List(Vertex(a, Geom3!u)), List(Face)) -> Mesh(a, Geom3!u)
Creates a mesh from vertices and faces
:: for_unit a, Geom3!u: (List(a*Geom3!u)) -> Path(a, Geom3!u)
Constructs a path from a list of points.
:: for_unit a, Geom3!u: (String) -> Scene(a, Geom3!u)
Constructs a scene.
The scene has ambient white light of intensity 0.3. Set the ambient light intensity to zero with function with_ambient_light to remove this default ambient light.
The argument is a description of the scene that can be used as a caption.
:: (1, 1, 1) -> Face
Creates a mesh face. Each argument is the index of a vertex. The mesh must contains sufficient vertices.
:: for_unit a, Geom3!u: (a*Geom3!u, a*Geom3!u, String, String, Color) -> Arrow(a, Geom3!u)
Constructor for record Arrow(a, Geom3!u)
:: (String) -> Color
Create a color from a html color string. For example make_color("#ffffff")
and make_color("white") both create the color white.
:: for_unit a, Geom3!u: (String, a*Geom3!u, Color, String, 1) -> Label(a, Geom3!u)
Constructor for record Label(a, Geom3!u)
:: for_unit a, Geom3!u: (a*Geom3!u, a*Geom3!u, Color) -> Path(a, Geom3!u)
A line between two points. Each point is indicated by a vector.
:: for_unit a, Geom3!u: (List(Vertex(a, Geom3!u)), List(Face), Maybe(a*Geom3!u), Tuple(radian, radian, radian), String, Boole, String) -> Mesh(a, Geom3!u)
Constructor for record Mesh(a, Geom3!u)
:: for_unit a, Geom3!u: (List(a*Geom3!u), Color) -> Path(a, Geom3!u)
Constructor for record Path(a, Geom3!u)
:: for_unit a, Geom3!u: (a*Geom3!u, a*Geom3!u, Color, candela) -> SpotLight(a, Geom3!u)
Constructor for record SpotLight(a, Geom3!u)
:: for_unit a, Geom3!u: (String, a*Geom3!u, a*Geom3!u, Color, String) -> Text(a, Geom3!u)
Constructor for record Text(a, Geom3!u)
:: for_unit a, Geom3!u: (Arrow(a, Geom3!u), a*Geom3!u, a*Geom3!u) -> Arrow(a, Geom3!u)
Updates the start and end position of the arrow
:: for_unit a, Geom3!u: (Mesh(a, Geom3!u), a*Geom3!u) -> Mesh(a, Geom3!u)
Moves a mesh by offset 'vec'.
:: for_unit a: (String, a, Color) -> Mesh(a, Geom3!)
The same as make_cube_mesh except the cube is also given a name. The name is used
during animation to locate it when updating the scene.
:: for_unit a, Geom3!u: (List(Vertex(a, Geom3!u)), List(Face), String) -> Mesh(a, Geom3!u)
The same as make_mesh except the mesh is also given a name. The name is used
during animation to locate it when updating the scene.
:: for_unit a, Geom3!u: (a*Geom3!u) -> Arrow(a, Geom3!u)
Creates an arrow from the origin to some point.
:: (1, 1, 1) -> Color
Create a color from rgb values in the range 0 to 255.
:: for_unit a, Geom3!u: (Mesh(a, Geom3!u), radian, radian, radian) -> Mesh(a, Geom3!u)
Rotates a mesh by radians.
:: for_unit a, Geom3!u: (Scene(a, Geom3!u)) -> List(Arrow(a, Geom3!u))
Getter for record Scene(a, Geom3!u)
:: for_unit a, Geom3!u: (Scene(a, Geom3!u)) -> List(Mesh(a, Geom3!u))
Getter for record Scene(a, Geom3!u)
:: for_unit a, Geom3!u: (Scene(a, Geom3!u)) -> List(Path(a, Geom3!u))
Getter for record Scene(a, Geom3!u)
:: for_unit a, Geom3!u: (Mesh(a, Geom3!u), Boole) -> Mesh(a, Geom3!u)
Copy of the mesh, but with the wireframe property changed.
Deprecated. Use with_mesh_wireframe instead
:: for_unit a, Geom3!u: (a*Geom3!u, Color) -> Vertex(a, Geom3!u)
Creates a mesh vertex. Expects x, y and z coordinates and a color. Is an
element of a Scene(a, Geom3!u) scene.
:: for_unit a, Geom3!u: (String, 1, Scene(a, Geom3!u)) -> Scene(a, Geom3!u)
Sets the ambient light of the scene. The intensity ranges from 1 to 5 (it seems).
:: for_unit a, Geom3!u: (Color, Arrow(a, Geom3!u)) -> Arrow(a, Geom3!u)
Setter for record Arrow(a, Geom3!u)
:: for_unit a, Geom3!u: (String, Arrow(a, Geom3!u)) -> Arrow(a, Geom3!u)
Setter for record Arrow(a, Geom3!u)
:: for_unit a, Geom3!u: (String, Arrow(a, Geom3!u)) -> Arrow(a, Geom3!u)
Setter for record Arrow(a, Geom3!u)
:: for_unit a, Geom3!u: (String, Mesh(a, Geom3!u)) -> Mesh(a, Geom3!u)
Setter for record Mesh(a, Geom3!u)
:: for_unit a, Geom3!u: (String, Mesh(a, Geom3!u)) -> Mesh(a, Geom3!u)
Setter for record Mesh(a, Geom3!u)
:: for_unit a, Geom3!u: (Boole, Mesh(a, Geom3!u)) -> Mesh(a, Geom3!u)
Setter for record Mesh(a, Geom3!u)
:: for_unit a, Geom3!u: (Color, Path(a, Geom3!u)) -> Path(a, Geom3!u)
Setter for record Path(a, Geom3!u)
:: for_unit a, Geom3!u: (List(Arrow(a, Geom3!u)), Scene(a, Geom3!u)) -> Scene(a, Geom3!u)
Setter for record Scene(a, Geom3!u)
:: for_unit a, Geom3!u: (List(Mesh(a, Geom3!u)), Scene(a, Geom3!u)) -> Scene(a, Geom3!u)
Setter for record Scene(a, Geom3!u)
:: for_unit a, Geom3!u: (List(Path(a, Geom3!u)), Scene(a, Geom3!u)) -> Scene(a, Geom3!u)
Setter for record Scene(a, Geom3!u)
Version v0.6.0, 2026-03-05T15:49:22.001110973+01:00[Europe/Amsterdam]