#! /bin/gawk -f # Last edited on 2003-04-07 04:15:41 by stolfi BEGIN { usage = ( \ "draw-lightballs \\\n" \ " [ -v scale=NUM ] \\\n" \ " < IMAGE.balls > IMAGE.pcmds" \ ); # Outputs a string of commands, suitable as the "-draw" option # of "convert", that draws labeled dots at the centers of # the bases of the light balls listed in "{IMAGE}.balls". # Assumes that it will be used on a copy of the image that has been # scaled by {scale}. labhsz = 50; # Label width in pixels labdh = 4; # Label H displacement in pixels labdv = 4; # Label V displacement in pixels abort = -1; } (abort >= 0) { exit abort; } (NF == 6) { if (($5 + 0) != 0) { data_error(("bad Z = \"" $5 "\"")); } h = int(scale*$1); v = int(scale*$2); x = $3; y = $4; z = $5; id = $6; # This assumes 6 pixels per character. (Depends on font...) labhsz = 6*length(id); labh = (h + labhsz + labdh >= 512 ? h - labhsz - labdh : h + labdh); labv = v - labdv; printf "circle %d,%d %d,%d text %d,%d \"%s\"\n", h,v, h+1,v, labh,labv, id; } END { if (abort >= 0) { exit abort; } } function data_error(msg) { printf "%d: **%s\n", FNR, msg > "/dev/stderr"; abort = 1; exit abort; } function arg_error(msg) { printf "**%s\n", msg > "/dev/stderr"; abort = 1; exit abort; }