-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfibonacci_word_fractal.sf
70 lines (56 loc) · 1.33 KB
/
fibonacci_word_fractal.sf
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
#!/usr/bin/ruby
# A modified Fibonacci word fractal, using Braille graphics.
var(m=14, scale=2) = ARGV.map{.to_i}...
(var world = Hash.new){0}{0} = 1
var loc = 0
var w = 1
var dir = Quadratic(0, 1, w)
var fib = ['1', '0']
func fib_word(n) {
fib[n] := (fib_word(n-1) + fib_word(n-2))
}
func step {
scale.times {
loc += dir
world{loc.im}{loc.re} = 1
}
}
var turns = [
Quadratic(0, 1, w),
-Quadratic(0, 1, w),
Quadratic(1, 0, w),
].shuffle
var n = 1
fib_word(m).each { |c|
if (c == '0') {
step()
dir *= turns[n % 3]
} else { ++n }
}
func braille_graphics(a) {
var (xlo, xhi, ylo, yhi) = +([Inf, -Inf]*2)...
a.each_key { |y|
ylo.min!(y.to_n)
yhi.max!(y.to_n)
a{y}.each_key { |x|
xlo.min!(x.to_n)
xhi.max!(x.to_n)
}
}
for y in (ylo .. (yhi, 4)) {
for x in (xlo .. (xhi, 2)) {
var cell = 0x2800
a{y+0}{x+0} && (cell += 1)
a{y+1}{x+0} && (cell += 2)
a{y+2}{x+0} && (cell += 4)
a{y+0}{x+1} && (cell += 8)
a{y+1}{x+1} && (cell += 16)
a{y+2}{x+1} && (cell += 32)
a{y+3}{x+0} && (cell += 64)
a{y+3}{x+1} && (cell += 128)
print cell.chr
}
print "\n"
}
}
braille_graphics(world)