-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcelhelper.sh
executable file
·98 lines (79 loc) · 3.25 KB
/
celhelper.sh
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
#!/bin/bash
# > celhelper.sh <
# Converts the code generated by Mike Swanson's Ai->Canvas Export Plug-In
# for Illustrator into an expression that stores the draw() function
# in a custom JavaScript array member.
# Storing these vector drawing instructions in an array gives me options
# for calling them sequentially in an animation.
# Learn more about the Ai->Canvas Export Plug-In at
# http://visitmix.com/labs/ai2canvas.
# Written by parisminton for Concrete Daydreams.
# <parisminton [at] da.ydrea.ms>
#vrs="v 0.3"
#last_change="12/8/11"
fileindex=0
args=($*)
# ...store arguments in a comma-separated string so we can declare our variables at the top of the function...
for ((i=0; i<${#args[*]}; i++ )); do
if [ "$arg_list_string" ]; then
arg_list_string=$(echo $arg_list_string | sed -n 's/\([a-zA-Z0-9_\-][a-zA-Z0-9_ \-\,]*\);$/\1, '"${args[$i]}"';/p')
else
arg_list_string="$1;"
fi
done
echo "function loadCharacters () {
var $arg_list_string
" >> cels.js
for ((j=0; j<${#args[*]}; j++)); do
arg_total=$(echo "${args[$j]}"* | wc -w)
echo " ${args[$j]} = new Character(\"${args[$j]}\", false);
${args[$j]}.show();
${args[$j]}.sequence.main.cels = [" >> cels.js
for file in ${args[$j]}*.html; do
# ... isolate the number in the filename. we'll use it to test if this is the last file of the sequence ...
sequence=$(echo "$file" | sed -n 's/^[a-zA-Z_.][a-zA-Z0-9.\-]*_\([0-9][0-9]*\)\.html$/\1/p')
if [ "$sequence" -eq $(($arg_total - 1)) ]; then
sed '
/function '"${args[$j]}"'/, /}$/ !d
s/ \/\// \/\//
s/ [a-zA-Z0-9]*(ctx) {$/ () {\
if \('"${args[$j]}"'.visible\) {/
s/ctx\./ ctx\./
s/ctx.lineWidth = \([0-9][0-9\.]*\);/'"${args[$j]}"'.lineWidth(\1);/
s/ctx.lineJoin = \("[a-z][a-z]*"\);/'"${args[$j]}"'.lineJoin(\1);/
s/ctx.miterLimit = \([0-9][0-9\.]*\);/'"${args[$j]}"'.miterLimit(\1);/
s/addColorStop(\([0-9][0-9\.]*, [a-z"][a-zA-Z0-9 #(),"]*\));/addColorStop(gradient, \1);/
s/ctx.fillStyle = \([a-z"][a-zA-Z0-9 #(),"]*\);/'"${args[$j]}"'.fillStyle(\1);/
s/ctx.strokeStyle = \([a-z"][a-zA-Z0-9 #(),"]*\);/'"${args[$j]}"'.strokeStyle(\1);/
s/ctx/'"${args[$j]}"'/
s/}$/ }\
}\
];\
/
' < $file >> cels.js
else
sed '
/function '"${args[$j]}"'/, /}$/ !d
s/ \/\// \/\//
s/ [a-zA-Z0-9]*(ctx) {$/ () {\
if \('"${args[$j]}"'.visible\) {/
s/ctx\./ ctx\./
s/ctx.lineWidth = \([0-9][0-9\.]*\);/'"${args[$j]}"'.lineWidth(\1);/
s/ctx.lineJoin = \("[a-z][a-z]*"\);/'"${args[$j]}"'.lineJoin(\1);/
s/ctx.miterLimit = \([0-9][0-9\.]*\);/'"${args[$j]}"'.miterLimit(\1);/
s/addColorStop(\([0-9][0-9\.]*, [a-z"][a-zA-Z0-9 #(),"]*\));/addColorStop(gradient, \1);/
s/ctx.fillStyle = \([a-z"][a-zA-Z0-9 #(),"]*\);/'"${args[$j]}"'.fillStyle(\1);/
s/ctx.strokeStyle = \([a-z"][a-zA-Z0-9 #(),"]*\);/'"${args[$j]}"'.strokeStyle(\1);/
s/ctx/'"${args[$j]}"'/
s/}$/ }\
},\
/
' < $file >> cels.js
fi
done
done
for ((l=0; l<${#args[*]}; l++ )); do
echo " ${args[$l]}.load();" >> cels.js
done
echo "
};" >> cels.js