|
|
1.1 ! root 1: /**************************************************************************** ! 2: ! 3: CALC.C -- ! 4: ! 5: Code to do the calculations for the Windows Mandelbrot Set distributed ! 6: drawing program. ! 7: ! 8: Copyright (C) 1990 Microsoft Corporation. ! 9: ! 10: This code sample is provided for demonstration purposes only. ! 11: Microsoft makes no warranty, either express or implied, ! 12: as to its usability in any given situation. ! 13: ! 14: ****************************************************************************/ ! 15: ! 16: #include <windows.h> ! 17: #include <malloc.h> // malloc, free ! 18: #include <stdio.h> ! 19: ! 20: #ifdef RPC ! 21: #include <rpc.h> ! 22: #include "mdlrpc.h" ! 23: #endif ! 24: ! 25: #include "mandel.h" ! 26: ! 27: void MandelCalc(PCPOINT pcptLL, ! 28: PLONGRECT prcDraw, ! 29: double precision, ! 30: DWORD ulThreshold, ! 31: PLINEBUF pbBuf) ! 32: { ! 33: DWORD h, height; ! 34: DWORD width; ! 35: PWORD pbPtr; ! 36: double dreal, dimag, dimag2; ! 37: short maxit = 0; ! 38: ! 39: pbPtr = (PWORD) pbBuf; // PLINEBUF points to the struct LINEBUF; ! 40: // LINEBUF is an array of WORDS ! 41: ! 42: dreal = pcptLL->real + ((double)prcDraw->xLeft * precision); ! 43: dimag = pcptLL->imag + ((double)prcDraw->yBottom * precision); ! 44: ! 45: maxit = (short) ulThreshold; ! 46: ! 47: height = (prcDraw->yTop - prcDraw->yBottom) + 1; ! 48: width = (prcDraw->xRight - prcDraw->xLeft) + 1; ! 49: ! 50: for ( ; width > 0; --width, dreal += precision) { ! 51: for (dimag2 = dimag, h = height; h > 0; --h, dimag2 += precision) ! 52: { ! 53: if ((dreal > 4.0) || (dreal < -4.0) || ! 54: (dimag2 > 4.0) || (dimag2 < -4.0)) ! 55: *(pbPtr++) = 0L; ! 56: else ! 57: *(pbPtr++) = (WORD) (calcmand(dreal, dimag2, maxit)); ! 58: } ! 59: } ! 60: return; ! 61: } ! 62: ! 63: ! 64: // midl requires these functions ! 65: // ==================================================================== ! 66: // MIDL allocate and free ! 67: // ==================================================================== ! 68: ! 69: ! 70: void * MIDL_user_allocate(unsigned long len) ! 71: { ! 72: return(PDWORD) (LocalLock(LocalAlloc(LMEM_MOVEABLE, len))); ! 73: } ! 74: ! 75: void MIDL_user_free(void * ptr) ! 76: { ! 77: LocalFree(ptr); ! 78: } ! 79: ! 80: /* C version of the assembly language program */ ! 81: ! 82: short calcmand(double dreal, double dimag, short maxit) ! 83: { ! 84: double x, y, xsq, ysq; ! 85: short k; ! 86: ! 87: k = (short) maxit; ! 88: x = dreal; ! 89: y = dimag; ! 90: ! 91: while (1) { ! 92: xsq = x * x; ! 93: ysq = y * y; ! 94: y = 2.0 * x * y + dimag; ! 95: x = (xsq - ysq) + dreal; ! 96: if (--k == 0) ! 97: return((short) (maxit - k)); ! 98: if ((xsq + ysq) > 4.0) ! 99: return((short) (maxit - k)); ! 100: } ! 101: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.