-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtile.scad
102 lines (81 loc) · 2.17 KB
/
tile.scad
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
// Grid of squares using random extruders, each square a random height
// Base height
_BaseHeight = 0.4;
// Square height multiplier
_SquareHeightMul = 0.6;
// Square width
_SquareWidth = 10;
// Square depth
_SquareDepth = 10;
// Square count, X
_SquareCountX = 20;
// Square count, Y
_SquareCountY = 20;
// Random seed for extruders
_SeedExtruder = 99;
// Random seed for heights
_SeedHeight = 13;
// 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 Base()
{
Extruder(1)
{
cube([_SquareWidth * _SquareCountX, _SquareDepth * _SquareCountY, _BaseHeight], center = false);
}
}
module Grid(Extruders, Heights)
{
for (X = [0 : _SquareCountX - 1])
{
for (Y = [0 : _SquareCountY - 1])
{
PointX = X * _SquareWidth;
PointY = Y * _SquareDepth;
translate([PointX, PointY, 0])
{
Ex = Extruders[X * _SquareCountX + Y];
Hi = Heights[X * _SquareCountX + Y];
Extruder(Ex)
{
cube([_SquareWidth, _SquareDepth, Hi], center=false);
}
}
}
}
}
module main()
{
// Generate a list of all needed random extruders
ExRand = rands(1, 6, _SquareCountX * _SquareCountY, _SeedExtruder);
Extruders = [for (i = [0 : (_SquareCountX * _SquareCountY) - 1]) floor(ExRand[i])];
// Generate a list of all needed random heights
ExHeight = rands(1, 5, _SquareCountX * _SquareCountY, _SeedHeight);
Heights = [for (i = [0 : (_SquareCountX * _SquareCountY) - 1]) floor(ExHeight[i]) * _SquareHeightMul];
Base();
translate([0, 0, _BaseHeight])
{
Grid(Extruders, Heights);
}
}
main();