commit 0a88bcecaedd27b2fea2b5923188d2819813530f Author: 45RPM Software Date: Tue Dec 14 18:40:24 2021 +0000 Add files via upload diff --git a/MandyWindow.c b/MandyWindow.c new file mode 100644 index 0000000..36d0409 --- /dev/null +++ b/MandyWindow.c @@ -0,0 +1 @@ +/***** * MandyWindow.c * * A simple fractal generator * * *****/ #include "mwMenus.h" #include "mwWindow.h" extern WindowPtr mwWindow; extern Rect dragRect; void InitMacintosh(void); void HandleMouseDown (EventRecord *theEvent); void HandleEvent(void); /* InitMacintosh() Initialize all the managers & memory */ void InitMacintosh(void) { MaxApplZone(); InitGraf(&thePort); InitFonts(); FlushEvents(everyEvent, 0); InitWindows(); InitMenus(); TEInit(); InitDialogs(0L); InitCursor(); } void HandleMouseDown (EventRecord *theEvent) { WindowPtr theWindow; int windowCode = FindWindow (theEvent->where, &theWindow); switch (windowCode) { case inSysWindow: SystemClick (theEvent, theWindow); break; case inMenuBar: AdjustMenus(); HandleMenu(MenuSelect(theEvent->where)); break; case inDrag: if (theWindow == mwWindow) DragWindow(mwWindow, theEvent->where, &dragRect); break; case inContent: if (theWindow == mwWindow) { if (theWindow != FrontWindow()) SelectWindow(mwWindow); else InvalRect(&mwWindow->portRect); } break; case inGoAway: if (theWindow == mwWindow && TrackGoAway(mwWindow, theEvent->where)) HideWindow(mwWindow); break; } } void HandleEvent(void) { int ok; EventRecord theEvent; HiliteMenu(0); SystemTask (); /* Handle desk accessories */ ok = GetNextEvent (everyEvent, &theEvent); if (ok) { switch (theEvent.what) { case mouseDown: HandleMouseDown(&theEvent); break; case keyDown: case autoKey: if ((theEvent.modifiers & cmdKey) != 0) { AdjustMenus(); HandleMenu(MenuKey((char) (theEvent.message & charCodeMask))); } break; case updateEvt: BeginUpdate(mwWindow); DrawContent(((WindowPeek) mwWindow)->hilited); EndUpdate(mwWindow); break; case activateEvt: InvalRect(&mwWindow->portRect); break; } } } void main(void) { InitMacintosh(); SetUpMenus(); SetUpWindow(); for (;;) { HandleEvent(); } } \ No newline at end of file diff --git a/mwMenus.c b/mwMenus.c new file mode 100644 index 0000000..45bdef4 --- /dev/null +++ b/mwMenus.c @@ -0,0 +1 @@ +/***** * mwMenus.c * * Routines for Mandy Fractal Generator menus. * *****/ #include "mwMenus.h" extern WindowPtr mwWindow; extern int width; MenuHandle appleMenu, fileMenu, editMenu, fractalMenu; enum { appleID = 1, fileID, editID, fractalID }; enum { openItem = 1, closeItem, quitItem = 4 }; /* SetUpMenus() Set up the menus. Normally, weÕd use a resource file, but for this example weÕll supply ÒhardwiredÓ strings. */ void SetUpMenus(void) { InsertMenu(appleMenu = NewMenu(appleID, "\p\024"), 0); InsertMenu(fileMenu = NewMenu(fileID, "\pFile"), 0); InsertMenu(editMenu = NewMenu(editID, "\pEdit"), 0); InsertMenu(fractalMenu = NewMenu(fractalID, "\pFractal"), 0); DrawMenuBar(); AddResMenu(appleMenu, 'DRVR'); AppendMenu(fileMenu, "\pOpen/O;Close/W;(-;Quit/Q"); AppendMenu(editMenu, "\pUndo/Z;(-;Cut/X;Copy/C;Paste/V;Clear"); AppendMenu(fractalMenu, "\pTree/T;Mandelbrot/M;Julia/J"); } /* AdjustMenus() Enable or disable the items in the Edit menu if a DA window comes up or goes away. Our application doesn't do anything with the Edit menu. */ static void enable (MenuHandle menu, short item, short ok); void AdjustMenus(void) { register WindowPeek wp = (WindowPeek) FrontWindow(); short kind = wp ? wp->windowKind : 0; Boolean DA = kind < 0; enable(editMenu, 1, DA); enable(editMenu, 3, DA); enable(editMenu, 4, DA); enable(editMenu, 5, DA); enable(editMenu, 6, DA); enable(fileMenu, openItem, !((WindowPeek) mwWindow)->visible); enable(fileMenu, closeItem, DA || ((WindowPeek) mwWindow)->visible); // CheckItem(widthMenu, width, true); } static void enable(MenuHandle menu, short item, short ok) { if (ok) EnableItem(menu, item); else DisableItem(menu, item); } /* HandleMenu(mSelect) Handle the menu selection. mSelect is what MenuSelect() and MenuKey() return: the high word is the menu ID, the low word is the menu item */ void HandleMenu (long mSelect) { int menuID = HiWord(mSelect); int menuItem = LoWord(mSelect); Str255 name; GrafPtr savePort; WindowPeek frontWindow; switch (menuID) { case appleID: GetPort(&savePort); GetItem(appleMenu, menuItem, name); OpenDeskAcc(name); SetPort(savePort); break; case fileID: switch (menuItem) { case openItem: ShowWindow(mwWindow); SelectWindow(mwWindow); break; case closeItem: if ((frontWindow = (WindowPeek) FrontWindow()) == 0L) break; if (frontWindow->windowKind < 0) CloseDeskAcc(frontWindow->windowKind); else if ((frontWindow = (WindowPeek) mwWindow) != NULL) HideWindow(mwWindow); break; case quitItem: ExitToShell(); break; } break; case editID: if (!SystemEdit(menuItem-1)) SysBeep(5); break; case fractalID: CheckItem(fractalMenu, width, false); width = menuItem; InvalRect(&mwWindow->portRect); break; } } \ No newline at end of file diff --git a/mwMenus.h b/mwMenus.h new file mode 100644 index 0000000..3924f69 --- /dev/null +++ b/mwMenus.h @@ -0,0 +1 @@ +/***** * mwMenus.h * * Public interfaces for mwMenus.h * ****/ void AdjustMenus(void); void HandleMenu (long mSelect); void SetUpMenus(void); \ No newline at end of file diff --git a/mwWindow.c b/mwWindow.c new file mode 100644 index 0000000..f5b407a --- /dev/null +++ b/mwWindow.c @@ -0,0 +1 @@ +/***** * mwWindow.c * * The window routines for the Mandy Fractal Generator * *****/ #include #include #include "mwWindow.h" #ifndef _Quickdraw_ #include #endif #define windowX 0 #define windowY 40 #define windowWidth 512 #define windowHeight 300 #define pi 3.14159265 WindowPtr mwWindow; Rect dragRect; Rect windowBounds = { windowY, windowX, windowY+windowHeight, windowX+windowWidth }; Rect imageStart = {0, 0, windowHeight, windowWidth}; int width = 5; /* SetUpWindow() Create the Minimum Window window, and open it. */ void SetUpWindow(void) { dragRect = screenBits.bounds; mwWindow = NewWindow(0L, &windowBounds, "\pFractal Window", true, noGrowDocProc, (WindowPtr) -1L, true, 0); SetPort(mwWindow); } void DrawBranch(float x1, float y1, float angle, float depth) { if (depth != 0) { float x2 = x1 + cos(angle*(pi/180.0))*depth*10; float y2 = y1 + sin(angle*(pi/180.0))*depth*10; MoveTo(x1,windowHeight-y1); Line(x2-x1,y1-y2); DrawBranch(x2,y2,angle-20,depth-1); DrawBranch(x2,y2,angle+20,depth-1); } } void Julia() { double cRe, cIm; //real and imaginary part of the constant c, determinate shape of the Julia Set double newRe, newIm, oldRe, oldIm; //real and imaginary parts of new and old double zoom = 1, moveX = 0, moveY = 0; //you can change these to zoom and change position int sizex = windowWidth, sizey = windowHeight; // ColorRGB color; //the RGB color value for the pixel int maxIterations = 300; //after how much iterations the function should stop int x,y; //pick some values for the constant c, this determines the shape of the Julia Set cRe = -0.7; cIm = 0.27015; //loop through every pixel for(x = 0; x < sizex; x+=2) for(y = 0; y < sizey; y+=2) { //i will represent the number of iterations int i; //calculate the initial real and imaginary part of z, based on the pixel location and zoom and position values newRe = 1.5 * (x - sizex / 2) / (0.5 * zoom * sizex) + moveX; newIm = (y - sizey / 2) / (0.5 * zoom * sizey) + moveY; //start the iteration process for(i = 0; i < maxIterations; i++) { //remember value of previous iteration oldRe = newRe; oldIm = newIm; //the actual iteration, the real and imaginary part are calculated newRe = oldRe * oldRe - oldIm * oldIm + cRe; newIm = 2 * oldRe * oldIm + cIm; //if the point is outside the circle with radius 2: stop if((newRe * newRe + newIm * newIm) > 4) break; } //draw the pixel if (i>4) { //6 //12 //24 MoveTo(x,y); if (i>32) { Line (1,0); MoveTo(x,y+1); Line (1,0); } else if (i>24) { Line (0,1); Line (1,0); } else if (i>12) { Line (1,0); } else if (i>6) { Line (1,1); } else { Line (0,0); } } } } void Mandelbrot() { //Mandelbrot int sizex = windowWidth, sizey = windowHeight; int maxiter = 64; int x = 0, y = 0; int zoom=150; for (x = 0; x < 2*(float)sizex; x+=2) { float xi = (float)x/zoom-2; for (y = 0; y < (float)sizey; y+=2) { float yi = (float)y / zoom; float px = 0; float py = 0; int i; for (i = 1; i < maxiter; i++) { float xt; if ( px*px+py*py > 4 ) { break; } xt = xi + px*px-py*py; py = yi + 2*px*py; px = xt; } if (i>4) { //6 //12 //24 MoveTo(x,(windowHeight/2)+y); if (i>32) { Line (1,0); MoveTo(x,(windowHeight/2)+y+1); Line (1,0); } else if (i>24) { Line (0,1); Line (1,0); } else if (i>12) { Line (1,0); } else if (i>6) { Line (1,1); } else { Line (0,0); } MoveTo(x,(windowHeight/2)-y); if (i>32) { Line (1,0); MoveTo(x,(windowHeight/2)-y-1); Line (1,0); } else if (i>24) { Line (0,1); Line (1,0); } else if (i>12) { Line (1,0); } else if (i>6) { Line (1,1); } else { Line (0,0); } } } } } /* DrawContent() Draws the content. */ void DrawContent(short active) { Rect myRect; SetPort(mwWindow); EraseRect(&imageStart); myRect = imageStart; if (width==1) { // correct this to be a real choice for DrawBranch(windowWidth/2,0,90,9); } else if (width==2) { Mandelbrot(); } else if (width==3) { Julia(); } } \ No newline at end of file diff --git a/mwWindow.h b/mwWindow.h new file mode 100644 index 0000000..8ae14fe --- /dev/null +++ b/mwWindow.h @@ -0,0 +1 @@ +/***** * mwWindow.h * * Public interfaces for mwWindow.c * *****/ void DrawContent (short active); void SetUpWindow(void); \ No newline at end of file