-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathgrowing_quads.scad
More file actions
145 lines (110 loc) · 4.43 KB
/
Copy pathgrowing_quads.scad
File metadata and controls
145 lines (110 loc) · 4.43 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// Increasingly wide quadrilaterals
// TODO
// - Option to create a reflected pair of patterns
// - Option for a spine between reflected pair
/* [Quads] */
// [Count]
_QuadCount = 5;
// [Height]
_QuadHeight = 100;
// [Bottom Thickness]
_QuadBottomThickness = 2.0;
// [Top Thickness]
_QuadTopThickness = 2.0;
// [Quad-to-quad Gap]
_QuadGap = 5;
// [Starting Top Width]
_QuadStartTopWidth = 10;
// [Starting Bottom Width]
_QuadStartBottomWidth = 15;
// [Additonal Top Width %]
_QuadAddTopWidthPct = 0.20;
// Additional Bottom Width %]
_QuadAddBottomWidthPct = 0.25;
/* [Extruders] */
// [Extruder 1]
_QuadExtruder1 = true;
// [Extruder 2]
_QuadExtruder2 = true;
// [Extruder 3]
_QuadExtruder3 = true;
// [Extruder 4]
_QuadExtruder4 = true;
// [Extruder 5]
_QuadExtruder5 = true;
// [Extruder to render]
_WhichExtruder = "All"; // ["All", 1, 2, 3, 4, 5]
// Map a value of Extruder to an OpenSCAD color
function ExtruderColor(Extruder) =
(Extruder == 1 ) ? "red" :
(Extruder == 2 ) ? "green" :
(Extruder == 3 ) ? "blue" :
(Extruder == 4 ) ? "pink" :
(Extruder == 5 ) ? "yellow" :
"purple" ;
// If _WhichExtruder is "All" or is not "All" and matches the requested extruder, render
// the child nodes.
module Extruder(DoExtruder)
{
color(ExtruderColor(DoExtruder))
{
if (_WhichExtruder == "All" || DoExtruder == _WhichExtruder)
{
children();
}
}
}
// Quad - Render a single quad, then recurse to render the next one at +X
module Quad(QuadCount, QuadN, Height, BottomThickness, TopThickness, Gap, TopWidth, BottomWidth, AddTopWidthPct, AddBottomWidthPct, BottomX, TopX, QuadExtruders)
{
echo("Quad(", "Count=", QuadCount, "N=", QuadN, "H=", Height, "BT=", BottomThickness, "TT=", TopThickness, "G=", Gap, "TW=", TopWidth, "BW=", BottomWidth, "ATWP=",AddTopWidthPct, "ABWP=", AddBottomWidthPct, "BX=", BottomX, "TX=", TopX, "Ex=", QuadExtruders, ")");
PT0 = [BottomX + 0, 0, 0];
PT1 = [BottomX + BottomWidth, 0, 0];
PT4 = [BottomX + 0, 0, BottomThickness];
PT5 = [BottomX + BottomWidth, 0, BottomThickness];
PT2 = [TopX + TopWidth, Height, 0];
PT3 = [TopX + 0, Height, 0];
PT6 = [TopX + TopWidth, Height, TopThickness];
PT7= [TopX + 0, Height, TopThickness];
PolyhedronPoints =
[
PT0, PT1, PT2, PT3, PT4, PT5, PT6, PT7
];
PolyhedronFaces =
[
[0, 1, 2, 3],
[4, 5, 1, 0],
[7, 6, 5, 4],
[5, 6, 2, 1],
[6, 7, 3, 2],
[7, 4, 0, 3]
];
Ex = ((QuadCount - QuadN) % len(QuadExtruders)) + 1;
Extruder(Ex)
{
polyhedron(PolyhedronPoints, PolyhedronFaces);
}
if (QuadN > 1)
{
Quad(QuadCount, QuadN - 1, Height, BottomThickness, TopThickness, Gap, TopWidth + (TopWidth * AddTopWidthPct), BottomWidth + (BottomWidth * AddBottomWidthPct), AddTopWidthPct, AddBottomWidthPct, BottomX + BottomWidth + Gap, TopX + TopWidth + Gap, QuadExtruders);
}
}
// Quads - Render QuadCount quads, starting at 0,0 and proceeding to +X
module Quads(QuadCount, QuadHeight, QuadBottomThickness, QuadTopThickness, QuadGap, QuadStartTopWidth, QuadStartBottomWidth, QuadAddTopWidthPct, QuadAddBottomWidthPct, QuadBottomX, QuadTopX, QuadExtruders)
{
Quad(QuadCount, QuadCount, QuadHeight, QuadBottomThickness, QuadTopThickness, QuadGap, QuadStartTopWidth, QuadStartBottomWidth, QuadAddTopWidthPct, QuadAddBottomWidthPct, QuadBottomX, QuadTopX, QuadExtruders);
}
module main(QuadCount, QuadHeight, QuadBottomThickness, QuadTopThickness, QuadGap, QuadStartTopWidth, QuadStartBottomWidth, QuadAddTopWidthPct, QuadAddBottomWidthPct, QuadExtruder1, QuadExtruder2, QuadExtruder3,QuadExtruder4, QuadExtruder5)
{
AllQuadExtruders =
[
QuadExtruder1 ? 1 : 0,
QuadExtruder2 ? 2 : 0,
QuadExtruder3 ? 3 : 0,
QuadExtruder4 ? 4 : 0,
QuadExtruder5 ? 5 : 0
];
QuadExtruders = [for (E = AllQuadExtruders) if (E != 0) E];
Quads(QuadCount, QuadHeight, QuadBottomThickness, QuadTopThickness, QuadGap, QuadStartTopWidth, QuadStartBottomWidth, QuadAddTopWidthPct, QuadAddBottomWidthPct, 0, 0, QuadExtruders);
}
main(_QuadCount, _QuadHeight, _QuadBottomThickness, _QuadTopThickness, _QuadGap, _QuadStartTopWidth, _QuadStartBottomWidth, _QuadAddTopWidthPct, _QuadAddBottomWidthPct, _QuadExtruder1, _QuadExtruder2, _QuadExtruder3,_QuadExtruder4, _QuadExtruder5);