Fred's ImageMagick Scripts



 

 

KALEIDOSCOPE


Applies a kaleidoscope effect to an image.

Download Script

last modified: May 30, 2008



USAGE: kaleidoscope [-s sides] [-c xc,yc] [-v vp] infile outfile
USAGE: kaleidoscope [-h or -help]

-s .... sides ......... sides; integer; sides>1; default=3
-c .... xc,yc ......... x,y center coordinates for the effect;
....................... integers>=0; default=image center
-v .... vp ............ virtual-pixel method;
....................... any non-background method

PURPOSE: To apply a kaleidoscope effect to an image.

DESCRIPTION: KALEIDOSCOPE applies a kaleidoscope effect to an image.

ARGUMENTS:

-s sides ... SIDES is the number of kaleidoscope sides. Values are integers greater than 1. The default=3

-c xc,yc ... XC,YC are the center coordinates for the kaleidoscope effect in the image. Values are integers. The default is the image center.

NOTE: The script is very slow due to the use of a complicated formula evaluated using -fx.

CAVEAT: No guarantee that this script will work on all platforms, nor that trapping of inconsistent parameters is complete and foolproof. Use At Your Own Risk.


EXAMPLES


Kaleidoscope
http://www.jhlabs.com/ip/filters/

Original

Arguments:
-s 3

Arguments:
-s 5

Arguments:
-s 7



What the script does is as follows:

  • Applies a complicated formulate to an image using -fx

This is equivalent to the following IM commands

  • pi2=`convert xc: -format "%[fx:2*pi]" info:`
  • dx="dx=i-$xc;"
  • dy="dy=j-$yc;"
  • rad="rad=hypot(dx,dy);"
  • tt="tt=mod((atan2(dy,dx)+$pi2)*$sides/($pi2),1.0);"
  • ang="ang=2*(tt<0.5?tt:1-tt);"
  • convert $infile -virtual-pixel $vp -monitor \
    -fx "$dx $dy $rad $tt $ang u.p{$xc+rad*cos(ang),$yc+rad*sin(ang)}" \
    $outfile