-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdiamonds.scad
More file actions
252 lines (209 loc) · 6.46 KB
/
Copy pathdiamonds.scad
File metadata and controls
252 lines (209 loc) · 6.46 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
/* Diamonds */
/*
* TODO
*
* Color modes for primary and filler diamonds work as follows:
*
* Random - Color for each diamond is chosen at random within the range of
* _FirstPrimaryDiamond to _LastPrimaryDiamond or _FirstFillerDiamond
* to _LastFillerDiamond.
*
* By Row - Colors cycle row by row within the respective ranges.
*
* By Col - Colors cycle column by column within the respective ranges.
*
* Diagonal - Colors cycle diagonally within the respective ranges.
*
* Diamond Wave - Colors cycle in a V-shaped wave.
*/
// Primary Diamond Size
PrimaryDiamondSize = 10;
// Primary Diamond Height
PrimaryDiamondHeight = 3;
// Filler Diamond Size
FillerDiamondSize = 6;
// Filler Diamond Height
FillerDiamondHeight = 3;
// Additional Rim Height
RimHeight = 0.5;
// Rim Thickness
RimThickness = 0.5;
// Column count
_CountX = 6;
// Row count
_CountY = 8;
// Row spacing
_SpaceY = 18;
// Column spacing
_SpaceX = 31;
/* [Multiple Extruders] */
// Primary diamond color mode
_PrimaryColorMode = "Random"; // ["Random", "By Row", "By Col", "Diagonal", "Diamond Wave"]
// Filler diamond color mode
_FillerColorMode = "Random"; // ["Random", "By Row", "By Col", "Diagonal", "Diamond Wave"]
// First primary diamond extruder
_FirstPrimaryExtruder = 1;
// Last primary diamond extruder
_LastPrimaryExtruder = 2;
// First filler diamond extruder
_FirstFillerExtruder = 3;
// Last filler diamond extruder
_LastFillerExtruder = 4;
// Rim extruder
_RimExtruder = 5;
// Random seed
_RandomSeed = 131313;
// [Extruder to render]
_WhichExtruder = "All"; // ["All", 1, 2, 3, 4, 5]
module EndCustomization(){}
// Compute values for use in color modes
_CenterX = floor(_CountX / 2);
_CenterY = floor(_CountY / 2);
// Return the extruder for the given color mode
function ExtruderForColorMode(ColorMode, X, Y, ExtruderGrid, FirstExtruder, LastExtruder) =
(ColorMode == "Random") ? ExtruderGrid[X][Y] :
(ColorMode == "By Row") ? FirstExtruder + Y % (LastExtruder - FirstExtruder + 1) :
(ColorMode == "By Col") ? FirstExtruder + X % (LastExtruder - FirstExtruder + 1) :
(ColorMode == "Diagonal") ? FirstExtruder + (X + Y) % (LastExtruder - FirstExtruder + 1) :
(ColorMode == "Diamond Wave") ? FirstExtruder + (min(X, _CountX - X) + Y) % (LastExtruder - FirstExtruder + 1) :
-1;
// Adjust Y so that the filler diamonds in the Diamond Wave pattern get the right colors
function AdjustYForColorMode(ColorMode, X, Y) =
(ColorMode == "Diamond Wave" && X >= _CenterX) ? Y + 1 : Y;
// Randomize
ZZZ = rands(0, 1, 1, _RandomSeed);
/* Generate random extruders/colors for primary diamonds */
_PrimaryExtruderGrid =
[
for (x = [1 : _CountX])
[
for (y = [1 : _CountY])
floor(rands(0, 1, 1)[0] * (_LastPrimaryExtruder - _FirstPrimaryExtruder + 1)) + _FirstPrimaryExtruder
]
];
/* Generate random extruders/colors for filler diamonds */
_FillerExtruderGrid =
[
for (x = [1 : _CountX + 1])
[
for (y = [1 : _CountY])
floor(rands(0, 1, 1)[0] * (_LastFillerExtruder - _FirstFillerExtruder + 1)) + _FirstFillerExtruder
]
];
// Map a value of _WhichExtruder to an OpenSCAD color
function ExtruderColor(Extruder) =
(Extruder == 1 ) ? "red" :
(Extruder == 2 ) ? "green" :
(Extruder == 3 ) ? "blue" :
(Extruder == 4 ) ? "pink" :
(Extruder == 5 ) ? "yellow" :
(Extruder == "All") ? "orange" :
"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 || DoExtruder == "All")
{
children();
}
}
}
module FlatDiamond(Size)
{
translate([Size/2, 0, 0])
{
union()
{
circle($fn=3, r=Size);
translate([-Size, 0, 0])
{
rotate([0 ,0, 60])
{
circle($fn=3, r=Size);
}
}
}
}
}
module Diamond(Size, Height, RimHeight, DiamondExtruder, RimExtruder)
{
union()
{
// The diamond
Extruder(DiamondExtruder)
{
linear_extrude(Height)
{
FlatDiamond(Size);
}
}
// The rim
Extruder(RimExtruder)
{
translate([0, 0, Height])
{
for (dd = [0 : 1.5 : 3])
{
linear_extrude(RimHeight)
{
difference()
{
FlatDiamond(Size - dd);
offset(delta=-RimThickness)
{
FlatDiamond(Size - dd);
}
}
}
}
}
}
}
}
/* Primary Diamonds */
module PrimaryDiamonds(CountX, CountY, SpaceX, SpaceY, ColorMode, FirstDiamondExtruder, LastDiamondExtruder, RimExtruder)
{
for (x = [0 : CountX - 1])
{
for (y = [0 : CountY - 1])
{
PtX = x * SpaceX;
PtY = y * SpaceY;
// Choose extruder
DiamondExtruder = ExtruderForColorMode(ColorMode, x, y, _PrimaryExtruderGrid, FirstDiamondExtruder, LastDiamondExtruder);
// Render primary diamond
translate([PtX, PtY, 0])
{
Diamond(PrimaryDiamondSize, PrimaryDiamondHeight, RimHeight, DiamondExtruder, RimExtruder);
}
}
}
}
/* Filler Diamonds */
module FillerDiamonds(CountX, CountY, SpaceX, SpaceY, ColorMode, FirstDiamondExtruder, LastDiamondExtruder, RimExtruder)
{
for (x = [0 : CountX - 1])
{
for (y = [0 : CountY - 1])
{
PtX = (x * SpaceX) + (SpaceX / 2);
PtY = (y * SpaceY) + (SpaceY / 2);
// Choose extruder
DiamondExtruder = ExtruderForColorMode(ColorMode, x + 1, AdjustYForColorMode(ColorMode, x, y), _FillerExtruderGrid, FirstDiamondExtruder, LastDiamondExtruder);
// Render filler diamond
translate([PtX, PtY, 0])
{
Diamond(FillerDiamondSize, FillerDiamondHeight, RimHeight, DiamondExtruder, RimExtruder);
}
}
}
}
module main()
{
PrimaryDiamonds(_CountX, _CountY, _SpaceX, _SpaceY, _PrimaryColorMode, _FirstPrimaryExtruder, _LastPrimaryExtruder, _RimExtruder);
FillerDiamonds(_CountX, _CountY, _SpaceX, _SpaceY, _FillerColorMode, _FirstFillerExtruder, _LastFillerExtruder, _RimExtruder);
}
main();