Repository navigation
Expand file tree
/
Copy pathflexi_arcs.scad
More file actions
421 lines (351 loc) · 10.6 KB
/
Copy pathflexi_arcs.scad
File metadata and controls
421 lines (351 loc) · 10.6 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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
// flexi_arcs.scad:
//
// Concentric rings, sliced into arcs, on optional base, with optional corners.
//
// TODO:
// - Option to split corners at 90, 180, 270
// - Option to color like a checkerboard
// - Generalize to use polygons instead of circles
// - Recursive pattern on corners
//
// - Cornered ring:
// Add patterns for center, or recursive
/* [Ring] */
// Radius of central circle
_CenterRadius = 30;
// Ring count
_RingCount = 12;
// Ring width
_RingWidth = 20;
// Ring height
_Height = 1.0; // [0.2 : 0.1 : 10]
// Inner step degrees
_InnerStepDegrees = 15; // [0 : 0.5 : 90]
// Outer step degrees
_OuterStepDegrees = 30; // [0 : 0.5 : 90]
// Inner to outer step transition ring
_InnerToOuter = 4;
// Arc inset
_ArcInset = 0.4; // [0.2 : 0.1 : 10]
// Ring style
_RingStyle = "Centered"; // ["Centered", "Cornered"]
/* [Base] */
// Render base
_RenderBase = true;
// Base height
_BaseHeight = 0.2; // [0.2 : 0.1 : 10]
// Base outset
_BaseOutset = 1.0;
/* [Rim] */
// Render rim
_RenderRim = true;
// Additional rim height
_RimHeight = 0.4; // [0.2 : 0.1 : 10]
// Rim thickness
_RimThickness = 0.4; // [0.2 : 0.1 : 10]
// Rim count
_RimCount = 3;
// Rim spacing
_RimSpacing = 1.0; //[0.2 : 0.1 : 10]
/* [Corners] */
// Render corners
_RenderCorners = false;
// Corner outset
_CornerOutset = 1.0;
/* [Extruders] */
// Extruder color mode
_ColorMode = "Random"; // ["Random", "Rings", "Rays"]
// first extruder
_FirstExtruder = 1;
// Last extruder
_LastExtruder = 4;
// Base extruder
_BaseExtruder = 5;
// Center extruder
_CenterExtruder = 1;
// Corner extruder
_CornerExtruder = 5;
// Rim extruder
_RimExtruder = 5;
// Random seed
_RandomSeed = 1313;
// [Extruder to render]
_WhichExtruder = "All"; // ["All", 1, 2, 3, 4, 5]
// 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" :
"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();
}
}
}
module RenderArc2D(ArcInset, InnerRadius, OuterRadius, StartAngle, ArcAngle)
{
if (InnerRadius > ArcInset)
{
rotate(StartAngle)
{
offset(delta=-ArcInset)
{
projection()
{
rotate_extrude(angle=ArcAngle, $fn=99)
{
difference()
{
square([OuterRadius, 30], center=false);
square([InnerRadius, 30], center=false);
}
}
}
}
}
}
}
module RenderArc(InnerRadius, OuterRadius, StartAngle, ArcAngle, ArcInset, Height, RenderRim, RimCount, RimSpacing, RimHeight, RimThickness, ArcExtruder, RimExtruder)
{
// Render basic arc
Extruder(ArcExtruder)
{
linear_extrude(Height)
{
RenderArc2D(ArcInset, InnerRadius, OuterRadius, StartAngle, ArcAngle);
}
}
// Render optional rim
if (RenderRim)
{
Extruder(RimExtruder)
{
translate([0, 0, Height])
{
linear_extrude(RimHeight)
{
for (r = [0 : RimCount - 1])
{
RS = -(r * RimSpacing);
RT = -RimThickness + RS;
difference()
{
offset(delta=RS)
{
RenderArc2D(ArcInset, InnerRadius, OuterRadius, StartAngle, ArcAngle);
}
offset(delta=RT)
{
RenderArc2D(ArcInset, InnerRadius, OuterRadius, StartAngle, ArcAngle);
}
}
}
}
}
}
}
}
// Render center - Four arcs
module RenderCenter(Radius, ArcInset, Height, RenderRim, RimCount, RimSpacing, RimHeight, RimThickness, CenterExtruder, RimExtruder)
{
for (Start = [0 : 90 : 360])
{
RenderArc(1, Radius, Start, 90, ArcInset, Height, RenderRim, RimCount, RimSpacing, RimHeight, RimThickness, CenterExtruder, RimExtruder);
}
}
function PickArcExtruder(ColorMode, Ring, Arc, FirstExtruder, LastExtruder) =
(ColorMode == "Random") ? floor(rands(0, 1, 1)[0] * (LastExtruder - FirstExtruder + 1)) + FirstExtruder :
(ColorMode == "Rings") ? Ring % (LastExtruder - FirstExtruder + 1) + FirstExtruder :
(ColorMode == "Rays") ? Arc % (LastExtruder - FirstExtruder + 1) + FirstExtruder :
0;
// Render one set of rings
module RenderRing(Ring, InnerRadius, OuterRadius, AngleStep, ArcInset, Height, RenderRim, RimCount, RimSpacing, RimHeight, RimThickness, ColorMode, FirstExtruder, LastExtruder, RimExtruder)
{
for (Arc = [ 0 : 360 / AngleStep - 1])
{
StartAngle = Arc * AngleStep;
ArcExtruder = PickArcExtruder(ColorMode, Ring, Arc, FirstExtruder, LastExtruder);
RenderArc(InnerRadius, OuterRadius, StartAngle, AngleStep, ArcInset, Height, RenderRim, RimCount, RimSpacing, RimHeight, RimThickness, ArcExtruder, RimExtruder);
}
}
// Render all of the rings
module RenderRings(CenterRadius, RingCount, RingWidth, ArcInset, Height, InnerToOuter, OuterStepDegrees, InnerStepDegrees, RenderRim, RimCount, RimSpacing, RimHeight, RimThickness, ColorMode, FirstExtruder, LastExtruder, RimExtruder)
{
for (Ring = [0 : RingCount - 1])
{
InnerRadius = CenterRadius + (RingWidth * Ring);
AngleStep = (Ring >= InnerToOuter) ? OuterStepDegrees : InnerStepDegrees;
RenderRing(Ring, InnerRadius, InnerRadius + RingWidth, AngleStep, ArcInset, Height, RenderRim, RimCount, RimSpacing, RimHeight, RimThickness, ColorMode, FirstExtruder, LastExtruder, RimExtruder);
}
}
// Render 2D corner
module RenderCorner2D(Diameter, CornerOutset, ArcInset)
{
difference()
{
square(Diameter + 2 * CornerOutset, center=true);
circle(d=Diameter + ArcInset, $fn=99);
}
}
// Render the corners
module RenderCorners(Diameter, CornerOutset, ArcInset, Height, RenderRim, RimCount, RimSpacing, RimHeight, RimThickness, CornerExtruder, RimExtruder)
{
Extruder(CornerExtruder)
{
linear_extrude(Height)
{
RenderCorner2D(Diameter, CornerOutset, ArcInset);
}
}
// Render optional rim
if (RenderRim)
{
Extruder(RimExtruder)
{
translate([0, 0, Height])
{
linear_extrude(RimHeight)
{
for (r = [0 : RimCount - 1])
{
RS = -(r * RimSpacing);
RT = -RimThickness + RS;
difference()
{
offset(delta=RS)
{
RenderCorner2D(Diameter, CornerOutset, ArcInset);
}
offset(delta=RT)
{
RenderCorner2D(Diameter, CornerOutset, ArcInset);
}
}
}
}
}
}
}
}
// Render the base, round or square
module RenderBase(BaseDiameter, BaseHeight, RenderCorners, CornerOutset, BaseExtruder)
{
translate([0, 0, -BaseHeight])
{
linear_extrude(BaseHeight)
{
Extruder(BaseExtruder)
{
if (RenderCorners)
{
square(BaseDiameter + 2 * CornerOutset, center=true);
}
else
{
circle(d=BaseDiameter, $fn=99);
}
}
}
}
}
module main(CenterRadius, RingCount, RingWidth, ArcInset, Height, InnerToOuter, OuterStepDegrees, InnerStepDegrees, RenderBase, BaseHeight, BaseOutset, RenderRim, RimCount, RimSpacing, RimHeight, RimThickness, RenderCorners, CornerOutset, Extruders)
{
/* Seed the Random number generator */
X = rands(0, 100, 1, _RandomSeed);
// Compute sizes
Diameter = 2 * (CenterRadius + RingCount * RingWidth);
BaseDiameter = Diameter + BaseOutset;
// Get extruders
RimExtruder = Extruders.RimExtruder;
BaseExtruder = Extruders.BaseExtruder;
CenterExtruder = Extruders.CenterExtruder;
ColorMode = Extruders.ColorMode;
FirstExtruder = Extruders.FirstExtruder;
LastExtruder = Extruders.LastExtruder;
CornerExtruder = Extruders.CornerExtruder;
if (CenterRadius > 0)
{
RenderCenter(CenterRadius, ArcInset, Height, RenderRim, RimCount, RimSpacing, RimHeight, RimThickness, CenterExtruder, RimExtruder);
}
RenderRings(CenterRadius, RingCount, RingWidth, ArcInset, Height, InnerToOuter, OuterStepDegrees, InnerStepDegrees, RenderRim, RimCount, RimSpacing, RimHeight, RimThickness, ColorMode, FirstExtruder, LastExtruder, RimExtruder);
if (RenderCorners)
{
RenderCorners(Diameter, CornerOutset, ArcInset, Height, RenderRim, RimCount, RimSpacing, RimHeight, RimThickness, CornerExtruder, RimExtruder);
}
if (RenderBase)
{
RenderBase(BaseDiameter, BaseHeight, RenderCorners, CornerOutset, BaseExtruder);
}
echo("BaseDiameter=", BaseDiameter);
}
_Extruders = object
(
ColorMode = _ColorMode,
FirstExtruder = _FirstExtruder,
LastExtruder = _LastExtruder,
CenterExtruder = _CenterExtruder,
BaseExtruder = _BaseExtruder,
RimExtruder = _RimExtruder,
CornerExtruder = _CornerExtruder
);
// Render ring centered
if (_RingStyle == "Centered")
{
// Centered ring
main(_CenterRadius, _RingCount, _RingWidth, _ArcInset, _Height, _InnerToOuter, _OuterStepDegrees, _InnerStepDegrees, _RenderBase, _BaseHeight, _BaseOutset, _RenderRim, _RimCount, _RimSpacing, _RimHeight, _RimThickness, _RenderCorners, _CornerOutset, _Extruders);
}
// Render ring broken into 4 quadrants, mapped to corners
if (_RingStyle == "Cornered")
{
// Compute sizes
Diameter = 2 * (_CenterRadius + _RingCount * _RingWidth);
BaseDiameter = Diameter + _BaseOutset;
BaseRadius = BaseDiameter / 2;
//
// Set up translations to render quadrants in corners:
//
// [0] - Q1 in Q3
// [1] - Q3 in Q1
// [2] - Q4 in Q2
// [3] - Q4 in Q2
//
MainTranslation =
[
[-BaseRadius, -BaseRadius],
[BaseRadius, BaseRadius],
[-BaseRadius, BaseRadius],
[BaseRadius, -BaseRadius]
];
CubeTranslation =
[
[-BaseRadius, -BaseRadius],
[0, 0],
[-BaseRadius, 0],
[0, -BaseRadius]
];
for (Q = [0 : 3])
{
intersection()
{
translate([MainTranslation[Q][0], MainTranslation[Q][1], 0])
{
main(_CenterRadius, _RingCount, _RingWidth, _ArcInset, _Height, _InnerToOuter, _OuterStepDegrees, _InnerStepDegrees, _RenderBase, _BaseHeight, _BaseOutset, _RenderRim, _RimCount, _RimSpacing, _RimHeight, _RimThickness, _RenderCorners, _CornerOutset, _Extruders);
}
translate([CubeTranslation[Q][0], CubeTranslation[Q][1], -_BaseHeight])
{
cube([BaseRadius, BaseRadius, 99], center=false);
}
}
}
}
// DEBUGGING
//RenderArc(30, 60, 0, 90, _Height, _RenderRim, _RimCount, _RimSpacing, _RimHeight, _RimThickness);