home *** CD-ROM | disk | FTP | other *** search
- /*
- This Genie will draw a Snowflake curve. Algorithm from Delahaye. Written by Don Cox.
- */
- /* $VER: Snowflake Apr 94 */
-
- /* call open('STDERR', "ram:SnowTrace", "W")
- trace r */
-
- msg = PDSetup.rexx(2,0)
- units = getclip(pds_units)
- if msg ~= 1 then exit_msg(msg)
-
- numeric digits 8
- cr = "0a"x
-
- call PDM_setbatchmode(0)
- call PDM_autoupdate(0)
-
- flakelist = "Koch Snowflake"||cr||"Anti-snowflake"||cr|| "Thicket"||cr|| "Forest"
- flaketype = pdm_SelectFromList("Select line type",19,11,0,flakelist)
- if flaketype = "" then exit_msg("No line type selected")
- flaketype = space(flaketype,0)
-
- pi = 3.14159
- pi2 = 6.28318
- cr = '0a'x
- psize = pdm_GetPageSize()
- pageX = word(psize,1)
- pageY = word(psize,2)
-
- order = getclip(pduserorder) /* how many repeats */
-
- if order = "" then order = 3
-
- call pdm_unselectobj()
- form = "Repeat process:"order
- setup = pdm_getform("Pattern Settings",7,form)
- if setup = '' then exit_msg()
- parse var setup order
-
- if ~(datatype(order, n)) then exit_msg("Invalid Entry")
-
- call setclip(pduserorder, order)
-
- b = pdm_getclickposn("Click top left corner position")
- posx = word(b,1)
- posy = word(b,2)
- call pdm_ShowStatus(" Working...")
- call pdm_UnselectObj()
- call pdm_initplot(posx,posy, 1,1,0)
-
- select
- when flaketype = "KochSnowflake" then do
- mainsides = 3 /* start with triangle */
- segments = 4 /* break each side into 4 */
- np = pageX*0.8
- x.0 = 0
- x.1 = np
- x.2 = np*0.5
- x.3 = 0
-
- y.0 = squareroot(3)/2*np
- y.1 = y.0
- y.2 = 0
- y.3 = y.0
-
- L. = 1/3
-
- a.0 = 0
- a.1 = pi/3
- a.2 = 0-a.1
- a.3 = 0
- end
-
- when flaketype = "Anti-snowflake" then do
- mainsides = 3
- segments = 4
- np = pageX*0.8
- x.0 = np
- x.1 = 0
- x.2 = np*0.5
- x.3 = np
-
- y.0 = squareroot(3)/2*np
- y.1 = y.0
- y.2 = 0
- y.3 = y.0
-
- L. = 1/3
-
- a.0 = 0
- a.1 = pi/3
- a.2 = 0-a.1
- a.3 = 0
- end
-
- when flaketype = "Thicket" then do
- mainsides = 4
- segments = 4
- np = pageX*0.8
- x.0 = 0
- x.1 = np
- x.2 = np
- x.3 = 0
- x.4 = 0
-
- y.0 = 0
- y.1 = 0
- y.2 = np
- y.3 = np
- y.4 = 0
-
- L. = 1/(2+2*cos(0.45*pi))
-
- a.0 = 0
- a.1 = 0.45*pi
- a.2 = 0-a.1
- a.3 = 0
- end
-
- when flaketype = "Forest" then do
- mainsides = 1
- segments = 4
- np = pageX*0.8
- x. = 0
-
- y.0 = np
- y.1 = 0-np
-
- L.0 = 1/3
- L.1 = L.0
- L.2 = squareroot(10)/9
- L.3 = 5/9
-
- a.0 = 0
- a.1 = pi/2
- a.2 = -(atan(3))
- a.3 = 0
- end
-
- otherwise NOP
- end
-
- points = 1
- identity = 1
-
- do k=0 to mainsides-1
- xd = x.k
- yd = y.k
- kk = k+1
- xa = x.kk
- ya = y.kk
- x0 = xd
- y0 = yd
- call plotpoint(x0,y0)
- if xa~=xd then a0 = atan((ya-yd)/(xa-xd))
- else a0 = pi/2 * sign(ya-yd)
- if (xa-xd)<0 then a0=a0+pi
- L0 = squareroot((xa-xd)**2 + (ya-yd)**2)
- do i=0 to segments**order -1
- LL=L0
- aa=a0
- t1 = i
- if order~= 0 then do j = (order-1) to 0 by -1
- r = segments**j
- t2 = trunc(t1/r)
- aa = aa+a.t2
- LL = LL*L.t2
- t1 = t1-t2*r
- end
- x0 = x0+LL*cos(aa)
- y0 = y0+LL*sin(aa)
- call plotpoint(x0,y0)
- end
- end
-
- object = pdm_EndPlot()
- curves.identity = object
-
- call pdm_SelectObj(curves.1,curves.identity)
- call pdm_GroupObj()
-
-
- exit_msg("Done")
-
-
- exit_msg: procedure expose units
- do
- parse arg message
- call pdm_ClearStatus()
- if message ~= '' then call pdm_Inform(1,message,)
- call pdm_AutoUpdate(1)
- call pdm_SetUnits(units)
- call pdm_SetBatchMode(0)
- exit
- end
-
-
-
- /* +++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++ */
-
- squareroot: /* to avoid bug in gdarexxsupport.library sqrt function */
- parse arg number
-
- removed = remlib("gdarexxsupport.library")
- if removed~=1 then call ppm_Inform(1,"Could not remove gdarexxsupport.library calculations may be faulty","Resume")
-
- /* rexxmathlib.library is needed instead */
- if ~show("l", "rexxmathlib.library") then
- if ~addlib("rexxmathlib.library", 0, -30,0) then do
- call ppm_Inform(1,"Please install the rexxmathlib.library in your libs: directory before running this Genie.")
- end
-
- number = sqrt(number)
-
- if ~show("l", "gdarexxsupport.library") then
- if ~addlib("gdarexxsupport.library", 0, -30,0) then do
- call ppm_Inform(1,"Please install the gdarexxsupport.library in your libs: directory before running this Genie.")
- end
-
-
- return number
-
- /* +++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++ */
-
- plotpoint:
- arg plotX,plotY
- call pdm_PlotLine(plotX" "plotY)
- points = points + 1
- if points>250 then do /* not too many points on curve */
- object = pdm_EndPlot()
- curves.identity = object
- identity = identity+1
- call pdm_initplot(posx,posy, 1,1,0)
- call pdm_PlotLine(plotX" "plotY)
- points = 1
- end
-
- return
-
- /* +++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++ */