home *** CD-ROM | disk | FTP | other *** search
- #include "common.h"
-
- /*--------------------------------------------------------------------*
- * Process the Duffing dialog proc. *
- *--------------------------------------------------------------------*/
- MRESULT EXPENTRY
- DuffingDlgProc(HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
- {
- char a[10], b[10], c[10], F[10];
- static double aval = 1.0, bval = 0.3, cval = 0.0, Fval = 10.0;
-
- switch (msg) {
- case WM_INITDLG:
- gcvt(aval, 5, a);
- gcvt(bval, 5, b);
- gcvt(cval, 5, c);
- gcvt(Fval, 5, F);
-
- WinSetDlgItemText(hwnd, DID_DUFF_a, a);
- WinSetDlgItemText(hwnd, DID_DUFF_b, b);
- WinSetDlgItemText(hwnd, DID_DUFF_c, c);
- WinSetDlgItemText(hwnd, DID_DUFF_F, F);
-
- WinSendDlgItemMsg(hwnd, DID_DUFF_a, EM_SETTEXTLIMIT,
- MPFROM2SHORT(9, 0), NULL);
- WinSendDlgItemMsg(hwnd, DID_DUFF_b, EM_SETTEXTLIMIT,
- MPFROM2SHORT(9, 0), NULL);
- WinSendDlgItemMsg(hwnd, DID_DUFF_c, EM_SETTEXTLIMIT,
- MPFROM2SHORT(9, 0), NULL);
- WinSendDlgItemMsg(hwnd, DID_DUFF_F, EM_SETTEXTLIMIT,
- MPFROM2SHORT(9, 0), NULL);
-
- case WM_COMMAND:
- switch (COMMANDMSG(&msg)->cmd) {
- case DID_CANCEL:
- WinDismissDlg(hwnd, TRUE);
- return 0;
- case DID_OK:
- WinQueryDlgItemText(hwnd, DID_DUFF_a, sizeof(a), a);
- WinQueryDlgItemText(hwnd, DID_DUFF_b, sizeof(b), b);
- WinQueryDlgItemText(hwnd, DID_DUFF_c, sizeof(c), c);
- WinQueryDlgItemText(hwnd, DID_DUFF_F, sizeof(F), F);
-
- tp.pvalue[0].d = aval = atof(a);
- tp.pvalue[1].d = bval = atof(b);
- tp.pvalue[2].d = cval = atof(c);
- tp.pvalue[3].d = Fval = atof(F);
- tp.exitflag = 0;
-
-
- DosSemSet(&tp.triggerdraw);
- DosSemClear(&tp.doingdraw);
-
- if (_beginthread(draw_duffing, 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 Duffing Oscillator *
- *--------------------------------------------------------------------*/
- void far
- draw_duffing(threadparms * tp)
- {
- HAB hab;
-
- POINTL ptl;
-
- double x, y, z, nx, ny, nz, t;
- double a, b, c, F;
- register int i;
-
- MATRIXLF transform;
-
-
- DosSemWait(&tp->triggerdraw, SEM_INDEFINITE_WAIT);
- DosSemSet(&tp->doingdraw);
-
- setfloatscale(&transform, -10., -10., 10., 10.,
- 2000, 2000, tp->xmax, tp->ymax);
-
-
- a = tp->pvalue[0].d;
- b = tp->pvalue[1].d;
- c = tp->pvalue[2].d;
- F = tp->pvalue[3].d;
-
- hab = WinInitialize(0);
-
- GpiSetDefaultViewMatrix(tp->memhps, 9L, &transform,
- TRANSFORM_REPLACE);
- GpiErase(tp->memhps);
- GpiSetColor(tp->memhps, CLR_RED);
-
- ptl.x = 0;
- ptl.y = -10 * 2000;
- GpiMove(tp->memhps, &ptl);
-
- ptl.x = 0;
- ptl.y = 10 * 2000;
- GpiLine(tp->memhps, &ptl);
-
- ptl.x = -10 * 2000;
- ptl.y = 0;
- GpiMove(tp->memhps, &ptl);
-
- ptl.x = 10 * 2000;
- ptl.y = 0;
- GpiLine(tp->memhps, &ptl);
-
- GpiSetColor(tp->memhps, CLR_DARKBLUE);
-
- x = -1.;
- y = 1.;
- z = 0;
- t = .004;
- for (i = 0; i < 10000; i++) {
- if (tp->exitflag)
- break;
- nx = x + t * y;
- ny = y + t * ( -(a*x*x*x + c*x + b*x) + F * cos(z));
- nz = z + t;
- x = nx;
- y = ny;
- z = nz;
- ptl.x = (x * 2000);
- ptl.y = (y * 2000);
- GpiSetPel(tp->memhps, &ptl);
- if( i % 100 == 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();
- }
-