-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcubeviz
executable file
·62 lines (50 loc) · 1.28 KB
/
cubeviz
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
#!/bin/sh
# Get images for a Rubik's cube state from http://cube.rider.biz/visualcube.php
# Can be used with a local installation of visualcube.
# Usage: cubeviz [type] [alg]
# See usage() for details
# Requires: curl, ImageMagick
visualcube="http://cube.rider.biz/visualcube.php"
usage() {
echo "Usage: cubeviz [type] [alg]"
echo "Types: trigger"
echo "Alg: use the standard notation"
}
trigger() {
alg="$(echo "$1" | tr "'" "3" | tr -d " ")"
w="wwwwwwwww"
y="yyyyyyyyy"
l="lllllllll"
d="ddddddddd"
t="ttttttttt"
ud="$visualcube?fmt=svg&fc=$y$l$l$y$l$l&size=200&view=plan"
top="$ud&alg=$alg"
bottom="$ud&alg=${alg}x2"
s="$visualcube?fmt=svg&fc=$y$t$t$y$t$t&size=200&r=y30x-30"
side="$s&co=30&alg=$alg"
d="pics_tmp"
f="trigger_$alg.png"
# We need some temporary files because visualcube is broken
# on Conrad's website and cannot output formats other than svg.
mkdir "$d"
curl "$top" > $d/top.svg
curl "$bottom" > $d/bottom.svg
curl "$side" > $d/side.svg
c="convert -density 400"
$c $d/top.svg $d/top.png
$c $d/bottom.svg $d/bottom.png
$c $d/side.svg $d/side.png
montage -tile 2x2 -mode concatenate \
$d/top.png $d/side.png $d/bottom.png $f
rm -r "$d"
}
[ -z "$2" ] && usage && exit 1
case "$1" in
trigger)
trigger "$2"
;;
*)
usage
exit 1
;;
esac