forked from JustinSDK/dotSCAD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vx_spiral_text.scad
60 lines (53 loc) · 1.77 KB
/
vx_spiral_text.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
use <hull_polyline2d.scad>;
use <voxel/vx_ascii.scad>;
tx = "3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172";
pts = [for(p = px_spiral(1, floor(sqrt(len(tx))) + 1)) p * 8];
linear_extrude(2)
for(i = [0:len(tx) - 1]) {
translate(pts[i])
difference() {
square(7, center = true);
render() for(p = vx_ascii(tx[i], center = true)) {
translate(p) square(.8);
}
}
}
linear_extrude(1) {
for(i = [0:len(tx) - 1]) {
translate(pts[i])
square(7, center = true);
}
hull_polyline2d([for(i = [0:len(tx) - 1]) pts[i]], width = 2);
}
function _px_spiral_forward(pt, leng, dir, clockwise) =
let(
DIRS = clockwise ? [
[1, 0],
[0, -1],
[-1, 0],
[0, 1]
]
: [
[1, 0],
[0, 1],
[-1, 0],
[0, -1]
]
)
pt + DIRS[dir] * leng;
function _px_spiral_go_turn(from, leng, max_leng, clockwise, dir) =
let(
range = [1:leng],
pts = [for(i = range) _px_spiral_forward(from, i, dir % 4, clockwise)],
ps = pts[len(pts) - 1],
pts2 = [for(i = range) _px_spiral_forward(ps, i, (dir + 1) % 4, clockwise)],
pd = pts2[len(pts2) - 1]
)
concat(pts, pts2, _px_spiral(pd, leng + 1, max_leng, clockwise, dir + 2));
function _px_spiral(from, leng, max_leng, clockwise, dir) =
leng > max_leng ? [] : _px_spiral_go_turn(from, leng, max_leng, clockwise, dir);
function px_spiral(init_leng, max_leng, clockwise = false) =
let(
org = [0, 0]
)
concat([org], _px_spiral(org, init_leng, max_leng, clockwise, 0));