-
Notifications
You must be signed in to change notification settings - Fork 0
/
design.stanza
91 lines (81 loc) · 4.97 KB
/
design.stanza
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
defpackage design :
import core
import collections
import math
import geom
import clipper
import font
import libfive
import classes
import utilities
import connection
import primitives
public defn write_design_debug (design:Design, filename:String) :
add_connectors(design)
set-resolution(1.0f)
for i in 0 to num_shapes(design) do :
to_stl(get_shape(design, i))
public defn write_design (design:Design, filename:String, num_slices:Int) :
add_connectors(design)
for i in 0 to num_shapes(design) do :
var shape = lay_flat(get_shape(design, i))
shape = mov-z(-1.0f * z(lo(bounds(shape))), shape)
var shape_thickness = range_axis(shape, z)
var slices = Array<Polygon>(num_slices)
for j in 1 to num_slices + 1 do :
var slc = slice(to-float(j) / to-float(num_slices + 1) * shape_thickness, shape)
slices[j - 1] = slc
to_svg(to-tuple(slices), "fabricationtest")
val pins = Array<Polygon>(numPins(design))
for i in 0 to numPins(design) do :
var pin = polygon-rect(V2f(woodThickness(design) / 8.0f * to-float(num_slices), woodThickness(design) / 8.0f))
pins[i] = pin
to_svg(to-tuple(pins), "pins")
public defn table_design (d:Float, jw:Float, wt:Float) :
val design = new_design(jw, wt)
val h_primitive = add_pins(extrude(woodThickness(design), rect(d, woodThickness(design))), design)
val v_primitive = add_pins(extrude(woodThickness(design), rect(woodThickness(design), d - 2.0f * woodThickness(design))), design)
val leg_primitive = add_pins(extrude(d, square(woodThickness(design))), design)
val h_side_bottom = mov-x(0.0f, h_primitive)
val edge_width = woodThickness(design) / 2.0f / d
val v_side_left = attach_shapes(v_primitive, V3f(0.5f, 0.0f, 0.5f), h_side_bottom, V3f(edge_width, 1.0f, 0.5f))
val v_side_right = attach_shapes(v_primitive, V3f(0.5f, 0.0f, 0.5f), h_side_bottom, V3f(1.0f - edge_width, 1.0f, 0.5f))
val h_side_top = attach_shapes(h_primitive, V3f(edge_width, 0.0f, 0.5f), v_side_left, V3f(0.5f, 1.0f, 0.5f))
val leg_1 = attach_shapes(leg_primitive, V3f(0.5f, 0.5f, 1.0f), h_side_bottom, V3f(edge_width, 0.5f, 0.0f))
val leg_2 = attach_shapes(leg_primitive, V3f(0.5f, 0.5f, 1.0f), h_side_bottom, V3f(1.0f - edge_width, 0.5f, 0.0f))
val leg_3 = attach_shapes(leg_primitive, V3f(0.5f, 0.5f, 1.0f), h_side_top, V3f(1.0f - edge_width, 0.5f, 0.0f))
val leg_4 = attach_shapes(leg_primitive, V3f(0.5f, 0.5f, 1.0f), h_side_top, V3f(edge_width, 0.5f, 0.0f))
val index_hb = add_shape(design, h_side_bottom)
val index_ht = add_shape(design, h_side_top)
val index_vl = add_shape(design, v_side_left)
val index_vr = add_shape(design, v_side_right)
val index1 = add_shape(design, leg_1)
val index2 = add_shape(design, leg_2)
val index3 = add_shape(design, leg_3)
val index4 = add_shape(design, leg_4)
add_connection(design, index_hb, index_vl, connection_point(bounds(h_side_bottom), V3f(edge_width, 1.0f, 0.5f)), V3f(0.0f, 1.0f, 0.0f), 0.0f, dovetail_dado_primitive)
add_connection(design, index_hb, index_vr, connection_point(bounds(h_side_bottom), V3f(1.0f - edge_width, 1.0f, 0.5f)), V3f(0.0f, 1.0f, 0.0f), 0.0f, dovetail_dado_primitive)
add_connection(design, index_ht, index_vl, connection_point(bounds(h_side_top), V3f(edge_width, 0.0f, 0.5f)), V3f(0.0f, -1.0f, 0.0f), 0.0f, dovetail_dado_primitive)
add_connection(design, index_ht, index_vr, connection_point(bounds(h_side_top), V3f(1.0f - edge_width, 0.0f, 0.5f)), V3f(0.0f, -1.0f, 0.0f), 0.0f, dovetail_dado_primitive)
add_connection(design, index1, index_hb, connection_point(bounds(h_side_bottom), V3f(edge_width, 0.5f, 0.0f)), V3f(0.0f, 0.0f, 1.0f), 0.0f, dovetail_dado_primitive)
add_connection(design, index2, index_hb, connection_point(bounds(h_side_bottom), V3f(1.0f - edge_width, 0.5f, 0.0f)), V3f(0.0f, 0.0f, 1.0f), 0.0f, dovetail_dado_primitive)
add_connection(design, index3, index_ht, connection_point(bounds(h_side_top), V3f(1.0f - edge_width, 0.5f, 0.0f)), V3f(0.0f, 0.0f, 1.0f), 180.0f, dovetail_dado_primitive)
add_connection(design, index4, index_ht, connection_point(bounds(h_side_top), V3f(edge_width, 0.5f, 0.0f)), V3f(0.0f, 0.0f, 1.0f), 180.0f, dovetail_dado_primitive)
design
;;to_stl(union([h_side_top, h_side_bottom, v_side_left, v_side_right, leg_1, leg_2, leg_3, leg_4]))
public defn grid_design () :
set-resolution(1.0f)
val outside = extrude(1.0f, circle(1.0f))
println(to-mesh(outside))
outside
public defn circle_design (diameter:Float, wood_thickness:Float, num_supports:Int) :
defn generate_support_bar (d_center:Float) :
pow(pow(diameter / 2.0f, 2.0f) + pow(d_center, 2.0f), 0.5f)
val design = new_design(wood_thickness, wood_thickness)
val spacing = diameter / to-float(num_supports + 1)
val horizontal_bars = Array<Shape>(num_supports)
val vertical_bars = Array<Shape>(num_supports)
;;for i in 1 to num_supports + 1 do :
;; horizontal_bars[i] = generate_support_bar(abs(to-float(i) * spacing - (diameter / 2.0f)))
;; vertical_bars[i] = generate_support_bar(abs(to-float(i) * spacing - (diameter / 2.0f)))
[]