scripts

Various scripts for UNIX-like systems
git clone https://git.tronto.net/scripts
Download | Log | Files | Refs | README

cubeviz (1306B)


      1 #!/bin/sh
      2 
      3 # Get images for a Rubik's cube state from http://cube.rider.biz/visualcube.php
      4 # Can be used with a local installation of visualcube.
      5 
      6 # Usage: cubeviz [type] [alg]
      7 # See usage() for details
      8 # Requires: curl, ImageMagick
      9 
     10 visualcube="http://cube.rider.biz/visualcube.php"
     11 
     12 usage() {
     13 	echo "Usage: cubeviz [type] [alg]"
     14 	echo "Types: trigger"
     15 	echo "Alg: use the standard notation"
     16 }
     17 
     18 trigger() {
     19 	alg="$(echo "$1" | tr "'" "3" | tr -d " ")"
     20 	w="wwwwwwwww"
     21 	y="yyyyyyyyy"
     22 	l="lllllllll"
     23 	d="ddddddddd"
     24 	t="ttttttttt"
     25 	ud="$visualcube?fmt=svg&fc=$y$l$l$y$l$l&size=200&view=plan"
     26 	top="$ud&alg=$alg"
     27 	bottom="$ud&alg=${alg}x2"
     28 	s="$visualcube?fmt=svg&fc=$y$t$t$y$t$t&size=200&r=y30x-30"
     29 	side="$s&co=30&alg=$alg"
     30 
     31 	d="pics_tmp"
     32 	f="trigger_$alg.png"
     33 
     34 	# We need some temporary files because visualcube is broken
     35 	# on Conrad's website and cannot output formats other than svg.
     36 	mkdir "$d"
     37 	curl "$top"    > $d/top.svg
     38 	curl "$bottom" > $d/bottom.svg
     39 	curl "$side"   > $d/side.svg
     40 
     41 	c="convert -density 400"
     42 	$c $d/top.svg $d/top.png
     43 	$c $d/bottom.svg $d/bottom.png
     44 	$c $d/side.svg $d/side.png
     45 
     46 	montage -tile 2x2 -mode concatenate \
     47 		$d/top.png $d/side.png $d/bottom.png $f
     48 
     49 	rm -r "$d"
     50 }
     51 
     52 [ -z "$2" ] && usage && exit 1
     53 
     54 case "$1" in
     55 	trigger)
     56 		trigger "$2"
     57 		;;
     58 	*)
     59 		usage
     60 		exit 1
     61 		;;
     62 esac