home *** CD-ROM | disk | FTP | other *** search
- #include "common.h"
- /*--------------------------------------------------------------------*
- * Handle the Henon dialog procedures *
- *--------------------------------------------------------------------*/
- MRESULT EXPENTRY
- HenonDlgProc(HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
- {
- char a[10], b[10];
- static double aval = 1.4, bval = 0.3;
- switch (msg) {
- case WM_INITDLG:
- gcvt(aval, 5, a);
- gcvt(bval, 5, b);
- WinSetDlgItemText(hwnd, DID_HENON_a, a);
- WinSetDlgItemText(hwnd, DID_HENON_b, b);
-
- WinSendDlgItemMsg(hwnd, DID_HENON_a, EM_SETTEXTLIMIT,
- MPFROM2SHORT(9, 0), NULL);
- WinSendDlgItemMsg(hwnd, DID_HENON_b, EM_SETTEXTLIMIT,
- MPFROM2SHORT(9, 0), NULL);
- return 0;
- case WM_COMMAND:
- switch (COMMANDMSG(&msg)->cmd) {
- case DID_CANCEL:
- WinDismissDlg(hwnd, TRUE);
- return 0;
- case DID_OK:
- WinQueryDlgItemText(hwnd, DID_HENON_a, sizeof(a), a);
- WinQueryDlgItemText(hwnd, DID_HENON_b, sizeof(b), b);
-
- tp.pvalue[0].d = aval = atof(a);
- tp.pvalue[1].d = bval = atof(b);
- tp.exitflag = 0;
-
-
- DosSemSet(&tp.triggerdraw);
- DosSemClear(&tp.doingdraw);
-
- if (_beginthread(draw_henon, threadstack,
- STACKSIZE * sizeof(int), &tp) == -1) {
- WinMessageBox(HWND_DESKTOP, hwnd,
- "Cannot create second thread!", "Thread2",
- 0, MB_OK | MB_ICONEXCLAMATION);
- return 0;
- }
- WinDismissDlg(hwnd, TRUE);
- setrunning();
- DosSemClear(&tp.triggerdraw);
- return 0;
- }
- break;
- }
- return WinDefDlgProc(hwnd, msg, mp1, mp2);
- }
- /*--------------------------------------------------------------------*
- * Draw the henon attractor *
- *--------------------------------------------------------------------*/
- void far
- draw_henon(threadparms * tp)
- {
- HAB hab;
-
- POINTL ptl;
-
- double x, y, nx, ny;
- double a, b;
- register int i;
-
- MATRIXLF transform;
-
-
- DosSemWait(&tp->triggerdraw, SEM_INDEFINITE_WAIT);
- DosSemSet(&tp->doingdraw);
-
- setfloatscale(&transform, -1.5, -.5, 1.3, .5,
- 1000, 1000, tp->xmax, tp->ymax);
-
-
- a = tp->pvalue[0].d;
- b = tp->pvalue[1].d;
-
- hab = WinInitialize(0);
-
- GpiSetDefaultViewMatrix(tp->memhps, 9L, &transform,
- TRANSFORM_REPLACE);
- GpiErase(tp->memhps);
- GpiSetColor(tp->memhps, CLR_RED);
-
- ptl.x = 0;
- ptl.y = -.5 * 1000;
- GpiMove(tp->memhps, &ptl);
-
- ptl.x = 0;
- ptl.y = .5 * 1000;
- GpiLine(tp->memhps, &ptl);
-
- ptl.x = -1.5 * 1000;
- ptl.y = 0;
- GpiMove(tp->memhps, &ptl);
-
- ptl.x = 1.3 * 1000;
- ptl.y = 0;
- GpiLine(tp->memhps, &ptl);
-
- GpiSetColor(tp->memhps, CLR_DARKBLUE);
-
- x = 1.5;
- y = 1.5;
- for (i = 0; i < 1000; i++) {
- if (tp->exitflag)
- break;
- nx = y + 1 - a * x * x;
- ny = b * x;
- x = nx;
- y = ny;
- ptl.x = x * 1000;
- ptl.y = y * 1000;
- GpiSetPel(tp->memhps, &ptl);
- if (i % 50 == 0) {
- refresh(tp->hps, tp->memhps, tp->cxmax, tp->cymax, tp->xmax, tp->ymax);
- }
- }
-
- DosSemSet(&tp->triggerdraw);
- DosSemClear(&tp->doingdraw);
-
- DosBeep(440, 200);
- WinPostMsg(hwndClient, WM_USER + 1, NULL, NULL);
- WinTerminate(hab);
- _endthread();
- }
-