home *** CD-ROM | disk | FTP | other *** search
- 18-Jun-88 14:29:29-MDT,5181;000000000000
- Return-Path: <u-lchoqu%sunset@cs.utah.edu>
- Received: from cs.utah.edu by SIMTEL20.ARPA with TCP; Sat, 18 Jun 88 14:29:20 MDT
- Received: by cs.utah.edu (5.54/utah-2.0-cs)
- id AA22218; Sat, 18 Jun 88 14:29:21 MDT
- Received: by sunset.utah.edu (5.54/utah-2.0-leaf)
- id AA24600; Sat, 18 Jun 88 14:29:19 MDT
- Date: Sat, 18 Jun 88 14:29:19 MDT
- From: u-lchoqu%sunset@cs.utah.edu (Lee Choquette)
- Message-Id: <8806182029.AA24600@sunset.utah.edu>
- To: rthum@simtel20.arpa
- Subject: FractalStack.c
-
- /*
- fractal xcmd v0.3 -- Doug Felt, Oct 14, 1987
-
- This draws a fractal on the screen. Not to the card, yet. Function is
- f(z) = z * z + c, julia set mapped to 4 patterns.
-
- Format:
- Fractal seed.h seed.v [res = 8 [limit = 32 [lock = 0]]]
-
- seed is the complex constant c (v imaginary)
- res is the number of pixels on a side for the point to plot
- limit is the max number of iterations (best between 16 & 128, multiple of 4),
- lower limit means most complex regions of the fractal are white
- if lock is 0, pressing the mouse will immediately stop the drawing, otherwise
- pressing the mouse has no effect and drawing can only be stopped by reboot or
- fancy macsbug work.
-
- Doug Felt, AIR/CAT Project
- duggie@jessica.stanford.edu
-
-
- To compile and link in MPW C:
-
- C -q2 Fractal.c
- link -sn Main=Fractal -sn STDIO=Fractal [line continuation symbol]
- -sn INTENV=Fractal -rt XCMD=104 [line continuation symbol]
- -m FRACTAL Fractal.c.o "{CLibraries}CRunTime.o" [line continuation symbol]
- -o HyperCommands
- */
-
- #include <Types.h>
- #include <Memory.h>
- #include <OSUtils.h>
- #include <QuickDraw.h>
- #include <Events.h>
- #include <HyperXCmd.h>
- pascal void Debugger() extern 0xA9FF;
-
-
- pascal void Fractal(paramPtr)
- XCmdBlockPtr paramPtr;
- {
- extended ParamToExt();
- long ParamToNum();
- int nolock,res,hsize,vsize,i,j,iter,limit,rbaseh;
- extended rat,seedh,seedv,valh,valv,temp,basev,baseh,hsq,vsq;
- extended real2,realn2,real100;
- long fake256,fake171,fake2,fake100;
- Rect r;
- struct _aPattern {
- long long1,long2;
- } pats[4];
-
- if (paramPtr->paramCount<2)
- return;
-
- pats[0].long1 = 0;
- pats[0].long2 = 0;
- pats[1].long1 = 0xaa005500;
- pats[1].long2 = 0xaa005500;
- pats[2].long1 = 0x55ffaaff;
- pats[2].long2 = 0x55ffaaff;
- pats[3].long1 = 0xffffffff;
- pats[3].long2 = 0xffffffff;
-
- res = 8;
- limit = 32;
- nolock = 1;
-
- seedh = ParamToExt(paramPtr,0);
- seedv = ParamToExt(paramPtr,1);
- if (paramPtr->paramCount>2) {
- res = ParamToNum(paramPtr,2);
- if (res <= 0)
- res = 1;
- }
-
- if (paramPtr->paramCount>3) {
- limit = ParamToNum(paramPtr,3);
- if (limit<4)
- limit = 4;
- }
-
- if (paramPtr->paramCount>4) {
- nolock = !ParamToNum(paramPtr,4);
- };
-
-
- /* map screen onto -2 to 2 range */
-
- /* 0,0 is at 512/2, 342/2 = 256,171 */
-
- /* gridding to res requires that I find out how many boxes wide and tall
- the image is, and map each box onto a value in r2. then i iterate over
- all the boxes calling the function until the x or y exceeds some limit.
- then i map the number of iterations into a 'color' */
-
- /* since we don't have a global data area for extended constants to live in,
- use longs and fake the compiler into making the correct SANE calls to
- build the extended values. Is there a better way (besides using Pascal!) */
-
- fake256 = 256;
- fake171 = 171;
- fake2 = 2;
- fake100 = 100;
-
- hsize = (fake256/res)+1; /* integer math truncates */
- vsize = (fake171/res)+1;
- real100 = fake100; /* fools the not-too-bright compiler. */
- real2 = fake2;
- realn2 = -fake2;
- rat = real2/hsize; /* reals intermediate result because of real2 */
-
- rbaseh = 256-hsize*res;
- r.top = 171-vsize*res;
- r.bottom = r.top + res;
- basev = realn2*fake171/fake256; /* center it */
-
- for (i=-vsize; i<vsize; ++i) {
- r.left = rbaseh;
- r.right = r.left + res;
- baseh = realn2;
- for (j=-hsize; j<hsize; ++j) {
- valh = baseh;
- valv = basev;
- iter = 0;
- do {
- hsq = valh * valh;
- vsq = valv * valv;
- temp = hsq - vsq + seedh;
- valv = real2*valh*valv + seedv;
- valh = temp;
- ++iter;
- } while ((hsq+vsq<real100) && (iter<limit));
-
- PenPat(&pats[iter & 0x03]);
- PaintRect(&r);
-
- r.left += res;
- r.right += res;
- baseh += rat;
- if (nolock && Button())
- return;
- }
- r.top += res;
- r.bottom += res;
- basev += rat;
- }
- }
-
-
- long ZeroToNum(paramPtr,zeroStr)
- XCmdBlockPtr paramPtr;
- char *zeroStr;
- {
- Str255 str;
-
- ZeroToPas(paramPtr,zeroStr,&str);
- return StrToNum(paramPtr,&str);
- }
-
- long ParamToNum(paramPtr,index)
- XCmdBlockPtr paramPtr;
- int index;
- {
- long ZeroToNum();
-
- return ZeroToNum(paramPtr,*(paramPtr->params[index]));
- }
-
- extended ZeroToExt(paramPtr,zeroStr)
- XCmdBlockPtr paramPtr;
- char *zeroStr;
- {
- Str255 str;
- extended res;
-
- ZeroToPas(paramPtr,zeroStr,&str);
- StrToExt(paramPtr,&str,&res);
- return res;
- }
-
- extended ParamToExt(paramPtr,index)
- XCmdBlockPtr paramPtr;
- int index;
- {
- extended ZeroToExt();
-
- return ZeroToExt(paramPtr,*(paramPtr->params[index]));
- }
-
-
- #include <XCmdGlue.inc.c>
-
-