-
Notifications
You must be signed in to change notification settings - Fork 2
/
sirpinski-stitch.ey
executable file
·138 lines (121 loc) · 3.54 KB
/
sirpinski-stitch.ey
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
#!./loaded
bin .print "<=" via
{ _ ==s len <=un16 s cat } /string deffd
{ ==divisor _ 0 lt { neg divisor div neg } { divisor div } ? * } '00.0 /idiv deffd
sys .argv len 3 neq { "Usage: ./sirpinsky-stitch.ey <μm cross size (try 500)> <output.vp3>" die } rep
sys .file "<-" via
"Scale μm: " 1 sys .argv * txt .consume .u 100 div _ ==scale 100 mul txt .produce .u cat dump
<-truncating <-creating <-writeonly 2 sys .argv * <-open
[
[ 500000000 866025403 neg ]
[ 1000000000 0 ]
[ 500000000 866025403 ]
[ 500000000 neg 866025403 ]
[ 1000000000 neg 0 ]
[ 500000000 neg 866025403 neg ]
] =*:DIRECTIONS
{ =*stitch
0 ==dir
{ =*curve { ==dAngle
dAngle neg curve
dir dAngle add =dir
dAngle curve
dir dAngle add =dir
dAngle neg curve
} } /recurse deffst
1
{ -- dir DIRECTIONS scale mul 1000000000 idiv 2 dearray stitch }
8 |recurse rep
*
} /produceImage deffd
0 ==xStart 0 ==yStart
0 ==minX 0 ==maxX 0 ==minY 0 ==maxY
{ ""
[ 10 246 0 ] str .fromArray cat # unknown
==data
list ==collectedData
{
stitch data -01 cat =data
data len 4096 gt {
data collectedData .append1
"" =data
} rep
} produceImage
"" collectedData { cat } each data cat
} /rawStitchContent deffst
< xStart ==x yStart ==y
{ ==dy ==dx
dx 128 neg gt dx 128 lt and
dy 128 neg gt dy 128 lt and and {
[ dx dy ] str .fromArray
} {
[ 128 1 ] str .fromArray dx <=sn16 dy <=sn16 [ 128 2 ] str .fromArray cat
} ? *
x dx add =x
y dy add =y
x minX lt { x =minX } rep
y minY lt { y =minY } rep
x maxX gt { x =maxX } rep
y maxY gt { y =maxY } rep
}
> -- /stitch deffd
rawStitchContent { }_ =*rawStitchContent
maxX minX sub ==xSize
maxY minY sub ==ySize
{ ""
minX neg xSize 2 div sub 100 mul <=sn32 # start X-offset
minY neg ySize 2 div sub 100 mul neg <=sn32 # start Y-offset
[ 1 0 ] str .fromArray cat # unknown
0 <=sn8 # red
0 <=sn8 # green
0 <=sn8 # blue
[ 0 0 0 5 40 ] str .fromArray cat # unknown
"1234" string # unknown numeric string
"Color name" string # unknown what values are acceptable
"Thread type" string # "Robison-Anton Rayon 40" in all generated files
0 <=sn32 # start x offset for next color
0 <=sn32 # start y offset for next color
"\0" string
rawStitchContent _ len "" -01 <=un32 -01 cat cat
} /stitchContent deffd
{ ""
0 <=sn32 # origin X
0 <=sn32 # origin Y
[ 0 0 0 ] str .fromArray cat # unknown
xSize 100 mul 2 div <=sn32
ySize 100 mul 2 div <=sn32
xSize 100 mul 2 div neg <=sn32
ySize 100 mul 2 div neg <=sn32
xSize 100 mul <=sn32
ySize 100 mul <=sn32
"Yet another comment" string
25700 <=un16 # unknown
4096 <=un32 # unknown
0 <=un32 # unknown
0 <=un32 # unknown
4096 <=un32 # unknown
"xxPP\0" cat # stitch section header
"Yet another vendor string" string
1 <=un16 # number of colors
[ 0 5 0 ] str .fromArray cat # unknown
stitchContent _ len 1 add "" -01 <=un32 -01 cat cat
} /innerContent deffd
{ ""
"File comments go here (or don't)" string
xSize 100 mul 2 div <=sn32
ySize 100 mul 2 div <=sn32
xSize 100 mul 2 div neg <=sn32
ySize 100 mul 2 div neg <=sn32
[ 0 0 122 134 ] str .fromArray cat # TODO thread length (ahem)
[ 0 ] str .fromArray cat # unknown
1 <=un8 # number of colors
[ 12 0 1 0 3 0 ] str .fromArray cat # unknown
innerContent _ len "" -01 <=un32 -01 cat cat
} /mainContent deffd
"%vsm%\0"
"Stratum 0 Embroidery Hack\0" string
[ 0 2 0 ] str .fromArray cat # unknown
mainContent _ len "" -01 <=un32 -01 cat cat
<-writeall
<-close
# vim: syn=elymas