gleamscad
A Gleam library for programmatically generating OpenSCAD files.
Features
- Type-safe OpenSCAD generation: Write OpenSCAD code in Gleam with compile-time checks.
- Easy integration: Use in any Gleam project targeting Erlang and JavaScript.
Supported feature set
Not every feature of OpenSCAD is supported yet. For a comparison of all features of OpenSCAD see: https://openscad.org/cheatsheet/
Boolean operations
- union()
- difference()
- intersection()
2D
- circle(radius | d=diameter)
- square(size,center)
- square([width,height],center)
- polygon([points])
- polygon([points],[paths])
- text(text,size,font,direction,language,script, halign,valign,spacing)
- import("….ext", convexity)
- projection(cut)
3D
- sphere(radius | d=diameter)
- cube(size, center)
- cube([width,depth,height], center)
- cylinder(h,r|d,center)
- cylinder(h,r1|d1,r2|d2,center)
- polyhedron(points, faces, convexity)
- import("….ext", convexity)
- linear_extrude(height,center,convexity,twist,slices)
- rotate_extrude(angle,convexity)
- surface(file = "….ext",center,convexity)
Transformations
translate([x,y,z])
rotate([x,y,z])
rotate(a, [x,y,z])
scale([x,y,z])
resize([x,y,z],auto,convexity)
mirror([x,y,z])
multmatrix(m)
color("colorname",alpha)
color("#hexvalue")
color([r,g,b,a])
offset(r|delta,chamfer)
hull()
minkowski(convexity)
Special variables
Example
gleam add gleamscad@1
import gleamscad as cad
pub fn main() {
cad.cube(12.34, cad.NotCentered)
|> cad.translate(1.0, 2.0, 3.0)
|> cad.rotate(90.0, 0.0, 0.0)
|> cad.to_openscad
|> echo
}
This will result in (indentations added for clarity):
rotate([90.0, 0.000000000, 0.000000000])
{
translate([1.0, 2.0, 3.0])
{
cube(size=[12.34, 12.34, 12.34], center=false);
}
}
Further documentation can be found at https://hexdocs.pm/gleamscad.
Development
gleam run # Run the project
gleam test # Run the tests