I had to tinker a while but I think I found a nice way to draw the pieces with ImageMagick's '-draw' operators.
Using the 'floodfill' didn't turn out too well. The line's anti-aliasing caused weird artifacts. (See previous post.) Instead of a square plus two lines, I switched to four triangles.Zooming in looks nicer.
Ha! Fun.
#!/bin/sh
# draw Vess Cola puzzle bottles
# davep 10-Jul-2011
SIZE=300
HALF=$(( ${SIZE}/2 ))
FOURTH=$(( ${SIZE}/4 ))
EIGHTH=$(( ${SIZE}/8 ))
THREEFOURTH=$(( ${FOURTH}/3 ))
function north {
if [ $1 == "bottom" ] ; then
echo "rectangle $(($HALF-$EIGHTH)),0 $(($HALF+$EIGHTH)),$FOURTH"
else
echo "polygon $(($HALF-$EIGHTH)),0 $(($HALF+$EIGHTH)),0 $HALF,$FOURTH"
fi
}
function east {
if [ $1 == "bottom" ] ; then
echo "rectangle $(($SIZE-$FOURTH)),$(($HALF-$EIGHTH)) $SIZE,$(($HALF+$EIGHTH))"
else
echo "polygon $SIZE,$(($HALF-$EIGHTH)) $SIZE,$(($HALF+$EIGHTH)) $(($SIZE-$FOURTH)),$HALF"
fi
}
function south {
if [ $1 == "bottom" ] ; then
echo "rectangle $(($HALF-$EIGHTH)),$(($SIZE-$FOURTH)) $(($HALF+$EIGHTH)),$SIZE"
else
echo "polygon $HALF,$(($SIZE-$FOURTH)) $(($HALF+$EIGHTH)),$SIZE $(($HALF-$EIGHTH)),$SIZE"
fi
}
function west {
if [ $1 == "bottom" ] ; then
echo "rectangle 0,$(($HALF-$EIGHTH)) $FOURTH,$(($HALF+$EIGHTH))"
else
echo "polygon 0,$(($HALF-$EIGHTH)) $FOURTH,$HALF 0,$(($HALF+$EIGHTH))"
fi
}
function piece {
num=$1
shift
convert -size $((${SIZE}+1))x$((${SIZE}+1)) xc:gray -fill white -stroke black \
-draw "rectangle 0,0 $SIZE,$SIZE" \
-fill $1 -draw "polygon 0,0 $SIZE,$0 $HALF,$HALF"\
-fill $3 -draw "polygon $SIZE,0 $SIZE,$SIZE $HALF,$HALF" \
-fill $5 -draw "polygon 0,$SIZE $SIZE,$SIZE $HALF,$HALF"\
-fill $7 -draw "polygon 0,0 0,$SIZE $HALF,$HALF"\
-fill black -draw "$(north $2)"\
-fill black -draw "$(east $4)"\
-fill black -draw "$(south $6)"\
-fill black -draw "$(west $8)"\
puzzlepiece${num}.png
}
piece 0 red bottom green top blue top yellow bottom
piece 1 red bottom blue bottom green top yellow top
piece 2 red top yellow top blue bottom green bottom
piece 3 green bottom blue bottom green top yellow top
piece 4 yellow bottom red top blue top red bottom
piece 5 green top yellow top red bottom blue bottom
piece 6 red top yellow top green bottom blue bottom
piece 7 blue top green bottom yellow bottom red top
piece 8 red top blue bottom yellow bottom green top
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.