-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathneg_shapes.scad
More file actions
380 lines (322 loc) · 7.48 KB
/
Copy pathneg_shapes.scad
File metadata and controls
380 lines (322 loc) · 7.48 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
// negative_shapes carved from a slab
//
// Final clip to get rid of element borders for partial elements
//
// Add texture to base
// Make texture height and thickness into parameters
// Better compute size
// Grid texture should be adjacent to cut lines
//
// Very fancy rotate
// MAJOR time - sequence through element shapes
// MID time - sequence through element sizes
// MINOR time - rotate 360
//
// Option to not do half-elements at each edge
/* [Base] */
// X count
_CountX = 10;
// Y count
_CountY = 10;
// X space
_SpaceX = 20;
// Y Space
_SpaceY = 20;
// Base thickness
_BaseThickness = 2;
// Gap
_BaseGap = 1;
// Cut in X direction
_CutX = true;
// Cut in Y direction
_CutY = true;
/* [Element] */
_ElementShape = "Circle"; // [Circle, Triangle, Square, Hexagon, Octagon]
// Element size
_ElementSize = 6;
// Element border
_ElementBorder = false;
// Element border thickness
_ElementBorderThickness = 2;
// Element border height
_ElementBorderHeight = 0.4;
/* [Texture] */
// Texture style
_TextureStyle = "None"; // [None, BaseRing, BaseGrid]
// Texture shape
_TextureShape = "None"; // [None, Circle, Triangle, Square, Hexagon, Octagon]
// Texture space
_TextureSpace = 4;
module __end_cust() {};
// Compute size of base
_BaseWidth = _CountX * (_SpaceX + _BaseGap);
_BaseDepth = _CountY * (_SpaceY + _BaseGap);
module Base(Width, Depth, Thickness)
{
color("blue")
{
cube([Width, Depth, Thickness]);
}
}
// Cuts in X or Y direction
module Cuts(XorY, Start, Count, Space, Width, Depth, Gap)
{
if (XorY == "X")
{
for (X = [0 : Count])
{
PointX = Start + (X * (Space + Gap)) - Gap / 2;
translate([PointX, 0, -99])
{
cube([Gap, Depth, 200]);
}
}
}
if (XorY == "Y")
{
for (Y = [0 : Count])
{
PointY = Start + (Y * (Space + Gap)) - Gap / 2;
translate([0, PointY, -99])
{
cube([Width, Gap, 200]);
}
}
}
}
// Render an element that will be used as anti-matter
module Element(Shape, Size, Thickness)
{
if (Shape == "Circle")
{
translate([0, 0, Thickness / 2])
{
cylinder(Thickness, r=Size, center=true);
}
}
if (Shape == "Triangle")
{
linear_extrude(Thickness)
{
circle(Size, $fn=3);
}
}
if (Shape == "Square")
{
linear_extrude(Thickness)
{
square(Size, Size, center=true);
}
}
if (Shape == "Hexagon")
{
linear_extrude(Thickness)
{
circle(Size, $fn=6);
}
}
if (Shape == "Octagon")
{
linear_extrude(Thickness)
{
rotate(22.5)
{
circle(Size, $fn=8);
}
}
}
}
// Render a grid of elements
module ElementGrid(CountX, CountY, SpaceX, SpaceY, BaseThickness, Gap, ElementShape, ElementSize)
{
for (X = [0 : CountX ])
{
for (Y = [0 : CountY])
{
// Compute center of cell
PointX = X * (SpaceX + Gap);
PointY = Y * (SpaceY + Gap);
translate([PointX, PointY, -.001])
{
Element(ElementShape, ElementSize, BaseThickness + .002);
}
}
}
}
// Render a grid of element borders
module ElementGridBorder(CountX, CountY, SpaceX, SpaceY, Gap, Shape, ElementSize, ElementBorderThickness, ElementBorderHeight)
{
Sides = ShapeToSides(Shape);
Angle = ShapeToAngle(Shape);
for (X = [0 : CountX ])
{
for (Y = [0 : CountY])
{
// Compute center of cell
PointX = X * (SpaceX + Gap);
PointY = Y * (SpaceY + Gap);
translate([PointX, PointY, 0])
{
linear_extrude(ElementBorderHeight)
{
difference()
{
circle(r=ElementSize + ElementBorderThickness, $fn=Sides);
circle(r=ElementSize, $fn=Sides);
}
}
}
}
}
}
// Map a texture shape to the number of sides
function ShapeToSides(Shape) =
(
(Shape == "None" ? 0 :
Shape == "Circle" ? 99 :
Shape == "Triangle" ? 3 :
Shape == "Square" ? 4 :
Shape == "Hexagon" ? 6 :
Shape == "Octagon" ? 8 :
0)
);
// Map a texture shape to rotation angle
function ShapeToAngle(Shape) =
(
(Shape == "None" ? 0 :
Shape == "Circle" ? 0 :
Shape == "Triangle" ? 0 :
Shape == "Square" ? 45 :
Shape == "Hexagon" ? 0 :
Shape == "Octagon" ? 22.5 :
0)
);
// Render a texture over the base
//
// Shape works for some of the styles, as follows:
//
// BaseRing - Each ring is the given Shape
//
module Texture(Shape, Width, Depth, Style, Space)
{
color("red")
{
if (Style == "None")
{
}
// A bunch of rings centered on the base
if (Style == "BaseRing")
{
Sides = ShapeToSides(Shape);
Angle = ShapeToAngle(Shape);
// TODO: Compute more accurate limits
for (r = [0 : Space : max(Width / 2, Depth / 2)])
{
linear_extrude(0.6)
{
difference()
{
// Matter
{
rotate(Angle)
{
circle(r + 1, $fn=Sides);
}
}
// Anti-matter
{
rotate(Angle)
{
circle(r, $fn=Sides);
}
}
}
}
}
}
if (Style == "BaseGrid")
{
// TODO
}
}
}
// Render base, elements, and texture
module BasePlusElements(BaseWidth, BaseDepth, BaseThickness, CountX, CountY, CutX, CutY, SpaceX, SpaceY, Gap, ElementShape, ElementSize, ElementBorder, ElementBorderThickness, ElementBorderHeight, TextureShape, TextureStyle, TextureSpace)
{
difference()
{
// Matter
{
union()
{
// Base
Base(BaseWidth, BaseDepth, BaseThickness);
// Texture
translate([BaseWidth / 2, BaseDepth / 2, BaseThickness])
{
Texture(TextureShape, BaseWidth, BaseDepth, TextureStyle, TextureSpace);
}
// Element borders
if (ElementBorder)
{
translate([0, 0, BaseThickness])
{
ElementGridBorder(CountX, CountY, SpaceX, SpaceY, Gap, ElementShape, ElementSize, ElementBorderThickness, ElementBorderHeight);
}
}
}
}
// Anti-matter
{
union()
{
// Cuts between elements (this looks wrong but it is not)
if (CutY)
{
Cuts("X", 0, CountX, SpaceX, BaseWidth, BaseDepth, Gap);
}
if (CutX)
{
Cuts("Y", 0, CountY, SpaceY, BaseWidth, BaseDepth, Gap);
}
// Elements
// 5 is a hack to make the elements tall enough to clip out texture
ElementGrid(CountX, CountY, SpaceX, SpaceY, BaseThickness + 5, Gap, ElementShape, ElementSize);
}
}
}
}
module main()
{
// If animating, use $t to determine rotation, element shape, and element size:
//
// SERRR
if ($t != 0)
{
T10K = $t * 10000;
echo(T10K);
//Rotation = ;
//Shape = ;
//Size = ;
// Use Rotation to change viewport not object
rotate( 0* 360)
{
translate([-_BaseWidth / 2, -_BaseDepth / 2, 0])
{
BasePlusElements(_BaseWidth, _BaseDepth, _BaseThickness, _CountX, _CountY, _CutX, _CutY, _SpaceX, _SpaceY, _BaseGap, _ElementShape, _ElementSize, _ElementBorder, _ElementBorderThickness, _ElementBorderHeight, _TextureShape, _TextureStyle, _TextureSpace);
}
}
}
else
{
translate([-_BaseWidth / 2, -_BaseDepth / 2, 0])
{
intersection()
{
BasePlusElements(_BaseWidth, _BaseDepth, _BaseThickness, _CountX, _CountY, _CutX, _CutY, _SpaceX, _SpaceY, _BaseGap, _ElementShape, _ElementSize, _ElementBorder, _ElementBorderThickness, _ElementBorderHeight, _TextureShape, _TextureStyle, _TextureSpace);
Base(_BaseWidth, _BaseDepth, 99); // HACK ^^ 99
}
}
}
}
main();