# 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.
[](https://hex.pm/packages/gleamscad)
[](https://hexdocs.pm/gleamscad/)
### Supported feature set
Not every feature of OpenSCAD is supported yet. For a comparison of all features of OpenSCAD see: [https://openscad.org/cheatsheet/](https://openscad.org/cheatsheet/)
#### Boolean operations
- [x] union()
- [x] difference()
- [x] intersection()
#### 2D
- [x] circle(radius | d=diameter)
- [ ] square(size,center)
- [x] square([width,height],center)
- [x] polygon([points])
- [ ] polygon([points],[paths])
- [ ] text(text,size,font,direction,language,script, halign,valign,spacing)
- [ ] import("….ext", convexity)
- [ ] projection(cut)
#### 3D
- [x] sphere(radius | d=diameter)
- [x] cube(size, center)
- [x] cube([width,depth,height], center)
- [x] cylinder(h,r|d,center)
- [x] cylinder(h,r1|d1,r2|d2,center)
- [ ] polyhedron(points, faces, convexity)
- [ ] import("….ext", convexity)
- [x] linear_extrude(height,center,convexity,twist,slices)
- [ ] rotate_extrude(angle,convexity)
- [ ] surface(file = "….ext",center,convexity)
#### Transformations
- [x] translate([x,y,z])
- [x] rotate([x,y,z])
- [ ] rotate(a, [x,y,z])
- [x] 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
```sh
gleam add gleamscad@1
```
```gleam
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):
```openscad
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
```sh
gleam run # Run the project
gleam test # Run the tests
```