home *** CD-ROM | disk | FTP | other *** search
- /*
-
- mandel.cwx
-
- Calculates and displays a subset of the Mandelbrot Set.
-
- Copyright 1997 by TrueSpectra Inc.
-
- This code is provided purely for demonstration purposes and is not
- supported or under warranty. Feel free to modify and examine this
- example script for your own purposes.
-
- */
-
-
- /* *********Edit these values to edit new regions.************/
- /* Resolution: */
- resx=16; resy=16 /* High rez.*/
- /*resx=8; resy=8*/ /* Low rez.*/
-
- cx=-0.782396718; cy=0.11763382; cw=0.012799782/resx; ch=0.012799782/resy
-
- /* Alternate set:*/
- /*cx=-2; cy=-1.7; cw=3.4/resx; ch=3.4/resy*/
-
-
- /******************* Editable section ends.********************/
-
-
- realx=1; realy=1
-
- call makerectangle realx*resx/2,realy*resy/2,realx*resx+realx/2,realy*resy+realy/2,0,0,0
-
- do xx=0 to resx-1
- do yy=0 to resy-1
- call tesselate xx*realx,yy*realy,realx,realy,xx*cw+cx,yy*ch+cy,cw,ch
- end /* do */
- end /* do */
-
- return
-
- /* subroutines */
- tesselate: procedure
- parse arg x,y,w,h,mx,my,mw,mh
-
- r5o4r2 = /* sqrt(5)/(4*sqrt(2)) */ 0.3952847
- r10 = /* sqrt(10) */ 3.1622777
- n1or10 = 1 / r10
- n3o4 = 3 / 4;
- n5o4 = 5 / 4;
- n3o4r10 = 0.2371708;
- n1mr10o2 = (1 - r10) / 4;
- n1pr10o3 = (1 + r10) / 3;
- n1pr10o2 = (1 + r10) / 2;
- q = 0.03
-
- /* A */
- /* rectangle */
- sx = x + 0.125 * w
- sy = y + 0.875 * h
- sw = (r5o4r2 - n5o4 * q) * w
- sh = (n1or10 - q) * h
- sa = 0.3217505
- ss = 0.6435011
- c = iterate( mx + 0.125 * mw, my + 0.875 * mh)
- if c\=0 then call makerectangle sx,sy,sw,sh,sa,ss,c
-
- /* B */
- /* triangle */
- sx = x + 0.375 * w
- sy = y + (0.9375 + n1mr10o2 * q) * h
- sw = ( 0.25 - n1pr10o3 * q) * w
- sh = ( 0.375 - n1pr10o2 * q) * h
- sa = 0
- ss = 0
- c = iterate( mx + 0.375 * mw, my + 0.9375 * mh)
- if c\=0 then call maketriangle sx,sy,sw,sh,sa,ss,c
-
- /* C */
- /* rectangle */
- sx = x + 0.625 * w
- sy = y + 0.875 * h
- sw = ( r5o4r2 - n5o4 * q) * w
- sh = ( n1or10 - q) * h
- sa = 1.8925469
- ss = 0.6435011
- c = iterate( mx + 0.625 * mw, my + 0.875 * mh)
- if c\=0 then call makerectangle sx,sy,sw,sh,sa,ss,c
-
- /* D */
- /* triangle */
- sx = x + 0.875 * w
- sy = y + (0.8125 - n1mr10o2 * q) * h
- sw = ( 0.25 - n1pr10o3 * q) * w
- sh = ( 0.375 - n1pr10o2 * q) * h
- sa = 3.1415927
- ss = 0
- c = iterate( mx + 0.875 * mw, my + 0.8125 * mh)
- if c\=0 then call maketriangle sx,sy,sw,sh,sa,ss,c
-
- /* E */
- /* triangle */
- sx = x + (0.0625 /*0.1875*/ - n1mr10o2 * q) * w
- sy = y + 0.625 * h
- sw = ( 0.25 - n1pr10o3 * q) * w
- sh = ( 0.375 - n1pr10o2 * q) * h
- sa = 1.5707963
- ss = 0
- c = iterate( mx + 0.1875 * mw, my + 0.625 * mh)
- if c\=0 then call maketriangle sx,sy,sw,sh,sa,ss,c
-
- /* F */
- /* rectangle */
- sx = x + 0.375 * w;
- sy = y + 0.625 * h;
- sw = ( 0.25 - q) * w;
- sh = ( 0.25 - q) * h;
- sa = 0;
- ss = 0;
- c = iterate( mx + 0.375 * mw, my + 0.625 * mh)
- if c\=0 then call makerectangle sx,sy,sw,sh,sa,ss,c
-
- /* G */
- /* triangle */
- sx = x + (0.6875 + n1mr10o2 * q) * w
- sy = y + 0.625 * h
- sw = ( 0.25 - n1pr10o3 * q) * w
- sh = ( 0.375 - n1pr10o2 * q) * h
- sa = -1.5707963
- ss = 0
- c = iterate( mx + 0.6875 * mw, my + 0.625 * mh)
- if c\=0 then call maketriangle sx,sy,sw,sh,sa,ss,c
-
- /* H */
- /* rectangle */
- sx = x + 0.125 * w
- sy = y + 0.375 * h
- sw = ( r5o4r2 - n5o4 * q) * w
- sh = ( n1or10 - q) * h
- sa = 1.8925469
- ss = 0.6435011
- c = iterate( mx + 0.125 * mw, my + 0.375 * mh)
- if c\=0 then call makerectangle sx,sy,sw,sh,sa,ss,c
-
- /* I */
- /* triangle */
- sx = x + 0.375 * w
- sy = y + (0.3125 - n1mr10o2 * q) * h
- sw = ( 0.25 - n1pr10o3 * q) * w
- sh = ( 0.375 - n1pr10o2 * q) * h
- sa = 3.1415927
- ss = 0
- c = iterate( mx + 0.375 * mw, my + 0.3125 * mh)
- if c\=0 then call maketriangle sx,sy,sw,sh,sa,ss,c
-
- /* J */
- /* rectangle */
- sx = x + 0.625 * w
- sy = y + 0.375 * h
- sw = ( r5o4r2 - n5o4 * q) * w
- sh = ( n1or10 - q) * h
- sa = 0.3217505
- ss = 0.6435011
- c = iterate( mx + 0.625 * mw, my + 0.375 * mh)
- if c\=0 then call makerectangle sx,sy,sw,sh,sa,ss,c
-
- /* K */
- /* triangle */
- sx = x + 0.875 * w
- sy = y + (0.4375 + n1mr10o2 * q) * h
- sw = ( 0.25 - n1pr10o3 * q) * w
- sh = ( 0.375 - n1pr10o2 * q) * h
- sa = 0
- ss = 0
- c = iterate( mx + 0.875 * mw, my + 0.4375 * mh)
- if c\=0 then call maketriangle sx,sy,sw,sh,sa,ss,c
-
- /* L */
- /* triangle */
- sx = x + (0.1875 + n1mr10o2 * q) * w
- sy = y + 0.125 * h
- sw = ( 0.25 - n1pr10o3 * q) * w
- sh = ( 0.375 - n1pr10o2 * q) * h
- sa = -1.5707963
- ss = 0
- c = iterate( mx + 0.1875 * mw, my + 0.125 * mh)
- if c\=0 then call maketriangle sx,sy,sw,sh,sa,ss,c
-
- /* M */
- /* triangle */
- sx = x + (0.5625 - n1mr10o2 * q) * w
- sy = y + 0.125 * h
- sw = ( 0.25 - n1pr10o3 * q) * w
- sh = ( 0.375 - n1pr10o2 * q) * h
- sa = 1.5707963
- ss = 0
- c = iterate( mx + 0.5625 * mw, my + 0.125 * mh)
- if c\=0 then call maketriangle sx,sy,sw,sh,sa,ss,c
-
- /* N */
- /* rectangle */
- sx = x + 0.875 * w;
- sy = y + 0.125 * h;
- sw = ( 0.25 - q) * w;
- sh = ( 0.25 - q) * h;
- sa = 0;
- ss = 0;
- c = iterate( mx + 0.875 * mw, my + 0.125 * mh)
- if c\=0 then call makerectangle sx,sy,sw,sh,sa,ss,c
-
- return
-
- iterate: procedure
- parse arg a,b
-
- ca = a
- cb = b
-
- do c = 1 to 250
- a2 = a*a
- b2 = b*b
-
- if a2+b2 > 4 then return c
-
- b = 2 * a * b + cb
- a = a2 - b2 + ca
- end
-
- return 0
-
- makerectangle: procedure
- parse arg x,y,w,h,r,s,c
-
- /* Make the object upright and set the Color */
- call CwSetSelectionRectangle x,y,w,h
- obj=CwCreateEffect("Rectangle","Solid Color")
- if r\=0 then call CwSetProperty obj,"Position:Angle",r/3.14152659878*180
- if s\=0 then call CwSetProperty obj,"Position:Skew",s/3.14152659878*180
- handle=CwGetTool(obj)
- call CwSetProperty handle,"Color",Colormap(c)
-
- return
-
- maketriangle: procedure
- parse arg x,y,w,h,r,s,c
-
- /* Make the object upright, and triangularm and set the Color */
- call CwSetSelectionRectangle x,y,w,h
- obj=CwCreateEffect("Shape","Solid Color")
- if r\=0 then call CwSetProperty obj,"Position:Angle",r/3.14152659878*180
- if s\=0 then call CwSetProperty obj,"Position:Skew",s/3.14152659878*180
- handle=CwGetRegion(obj)
- call CwSetProperty handle,"Shape","Triangle Cut-out"
- handle=CwGetTool(obj)
- call CwSetProperty handle,"Color",Colormap(c)
-
- return
-
- Colormap: procedure
- parse arg c
-
- if c=0 then return "#000000"
- Colorfrom=x2d('ff0000')
- Colorto=x2d('0080ff')
- return '#'d2x(trunc(Colorfrom*(250-c)/249+Colorto*(c-1)/249),6)
-
-