/
dragon_fractal_position.mbl
80 lines (80 loc) · 1.33 KB
/
dragon_fractal_position.mbl
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
# prints the X Y coordinates of the nth vertex in the Dragon Curve Fractal
#
# original code by Christopher Night
# modified by Sparr
#
# Usage:
# to print the first 32 vertices:
# seq 32 | xargs -n1 python -O marbelous.py dragon_fractal_position.mbl
# to produce a png with gnuplot:
# seq 32 | xargs -n1 python -O marbelous.py dragon_fractal_position.mbl | gnuplot -e "set terminal png;set output 'dragon.png';unset key;unset tics;unset border;plot '-' w l notitle"
#
# main board
# uses Dr to produce the X and Y coordinates
# prints X, then space, then Y, then \n
.. .. 0A
}0 .. ..
Dr Dr 20
Dp .. ..
.. .. ..
.. Dp ..
# calls Dragon with (0,0,n), adds 127 to both outputs
:Dr
}0 }0 }0 }0 }0
?0 ?0 .. ?0 ?0
.. .. .. -- --
Dr ag on >> >>
{0 {1 .. {0 {1
# Dragon recursively calls itself
:Dragon
}0 }1 }2 .. ..
.. .. -- }2 ..
Dr ag on =0 ..
{0 {1 .. {2 St
.. .. /\ .. //
.. /\ ++ \\ ..
Dg }0 Dg }1 ..
{0 // {1 // {2
# Handy function for converting directions (0-3 mod 4) into x/y offsets
:Dg
}0
>>
M2
<<
--
{0
# Direction of }0'th fold in the dragon curve (1 or -1)
:St
.. }0 ..
.. Np }0
.. << ~~
.. ++ //
.. St ..
}0 ~~ ..
Pw ++ ..
=0 {0 ..
\/ .. ..
# Largest power of 2 <= }0
:Np
}0 ..
>2 {0
>> ..
Np ..
<< ..
{0 ..
# Is }0 a power of 2?
:Pw
}0 .. }0
<2 >> M2
{0 .. >0
.. Pw --
.. {0 {0
# }0 mod 2
:M2
}0 ..
>> }0
<< ..
~~ ..
++ //
{0 ..
#include dec_out.mbl