macintosh@felix.UUCP (10/19/86)
[Moire Idle DAs (Sources) - Uploaded from Delphi by Jeff Shulman] Name: MOIRE IDLE DESK ACCESSORIES Date: 12-OCT-1986 20:05 by RMUHA Two more idle DAs. Moire.da bounces two points (random speeds) and inscribes objects within the generated rectangles. Poly.da bounces up to ten points and connects the dots. See the notes file for keyboard commands for each DA. The source consists of three files: idler.c - a common DA shell that may be used for writing other DAs. moire.c - drawing routines for moire.da poly.c - drawing routines for poly.da [Binaries have been posted to mod.mac.binaries. -RLL] --- #!/bin/sh # shar: Shell Archiver # Run the following text with /bin/sh to create: # Idle_Notes # Idler.c # Moire.c # Poly.c sed 's/^X//' << 'SHAR_EOF' > Idle_Notes XTwo more idle DAs. X XMoire.da bounces two points (random speeds) and inscribes objects within the generated rectangles. X '[' and ']' shorten and lengthen the queue. X'q' toggles speed quantization. X'0' thru '9' set a speed limit for points ('0' means none). XOther keys change shape: X'r' - rectangle (default for unassigned keys) X'o' - oval X'd' - diamond X't' - triangle X'p' - pentagram (for satanic users) X'h' - hourglass X'v' - a vee X'x' - an ex X'/' & '\' - slanted lines X XPoly.da bounces up to ten points and connects the dots. X'[' and ']' shorten and lengthen the queue. X'q' toggles speed quantization X'0' - '9' set the # points in the polygon ('0' and '1' mean 10) X XThe source consists of three files: Xidler.c - a common DA shell that may be used for writing other DAs. Xmoire.c - drawing routines for moire.da Xpoly.c - drawing routines for poly.da X XProduced using LightSpeed* C! X X XSHAR_EOF sed 's/^X//' << 'SHAR_EOF' > Idler.c X/* X * shell routine for idle DAs X */ X#include <hd20:lightspeed:mac:DeviceMgr.h> X#include <hd20:lightspeed:mac:WindowMgr.h> X#include <hd20:lightspeed:mac:EventMgr.h> X#include <hd20:lightspeed:mac:MenuMgr.h> X Xmain(cp, dp, entry) XcntrlParam *cp; XDCtlPtr dp; Xint entry; X{ X EventRecord *ep; X static Rect screen; X static Handle menuH; X static WindowPtr windP; X static Boolean active = false; X X X if (!dp->dCtlStorage) { X if (!entry) X CloseDriver(dp->dCtlRefNum); X return 0; X } X switch (entry) { X case 0: /* open */ X dp->dCtlFlags |= dNeedLock | dNeedTime; X dp->dCtlDelay = 0; X dp->dCtlEMask = everyEvent; X X GetWMgrPort(&windP); X screen = windP->portRect; X windP = NewWindow(0L, &screen, "\p", true, noGrowDocProc, -1L, true, 0L); X RectRgn(windP->visRgn, &screen); X ((WindowPeek) windP)->windowKind = dp->dCtlRefNum; X X initIdle(&screen); X break; X case 2: /* control */ X SetPort(windP); X switch (cp->csCode) { X case accRun: X if (active) X runIdle(&screen); X break; X case accEvent: X ep = (EventRecord *)*(long *)&cp->csParam; X switch (ep->what) { X case activateEvt: X menuH = GetMenuBar(); X ClearMenuBar(); X PaintRect(&screen); X PenMode(patXor); X active = true; X break; X case keyDown: X if (!active || keyIdle((int)(ep->message & charCodeMask)) >= 0) X break; X case mouseDown: X CloseDriver(dp->dCtlRefNum); X break; X } X break; X } X break; X X case 4: /* close */ X DisposeWindow(windP); X SetMenuBar(menuH); X DisposHandle(menuH); X DrawMenuBar(); X break; X } X return 0; X} SHAR_EOF sed 's/^X//' << 'SHAR_EOF' > Moire.c X/* X * moire idle desk accessory X * X * bounce points with random speeds X * generate queue of rectangles X * inscribe shapes within rectangles X * draw in XOR mode so stuff at end of queue can be erased X * X * keyboard commands: X * X * [ shorten queue X * ] lengthen queue X * q quantize point speed X * 0-9 set limit for point speed (0 means none) X * X * other keys select shapes (default is rectangle) X * o oval X * t tri-angle X * p penta-gram X * ... X */ X#include <hd20:lightspeed:mac:quickdraw.h> X X#define nQueue 100 /* max size of queue */ X#define qInit 30 /* initial size of queue */ X#define qIncr 10 /* size increment */ X Xint shape; /* current shape */ Xint quantize; /* quantize delta's */ Xlong limit; /* limit for delta's */ X/* X * bouncing points - 1st is value, 2nd is delta, each w/16 bit fraction X */ Xlong x1[2], y1[2], X x2[2], y2[2]; X/* X * rectangle queue X */ Xint qHead, qTail, qSize, nRinQ; XRect rQueue[nQueue]; X/* X * compute new delta X */ Xlong XnewDelta(range) X{ X register int r; X register long d; X X if ((r = Random()) < 0) X r = -r; X d = ((long)range << 16) / (r % range + 1); X if (quantize && (d = (d + 0x7FFFL) & ~0xFFFFL) == 0) X d = 0x10000L; X if (limit && d > limit) X d = limit; X return d; X} X/* X * compute new point value - change delta at rails X */ XnewPoint(p, lo, hi) Xlong *p; Xint lo, hi; X{ X register int v; X X v = p[0] >> 16; X if (v < lo) { X v = lo; X p[1] = newDelta(hi - lo); X } X else if (v > hi) { X v = hi; X p[1] = -newDelta(hi - lo); X } X p[0] += p[1]; X return v; X} X/* X * draw the current shape X */ XframeShape(s, rp) Xint s; XRect *rp; X{ X register int m, n; X X m = rp->left + (rp->right - rp->left) / 2; X n = rp->top + (rp->bottom - rp->top) / 2; X switch (s) { X default: X FrameRect(rp); X break; X case 'o': X FrameOval(rp); X break; X case 't': /* tri-angle */ X MoveTo(m, rp->top); X LineTo(rp->left, rp->bottom); X LineTo(rp->right, rp->bottom); X LineTo(m, rp->top); X break; X case 'p': /* pentagram */ X MoveTo(m, rp->top); X LineTo(rp->right, rp->bottom); X LineTo(rp->left, n); X LineTo(rp->right, n); X LineTo(rp->left, rp->bottom); X LineTo(m, rp->top); X break; X case 'd': /* diamond */ X MoveTo(m, rp->top); X LineTo(rp->right, n); X LineTo(m, rp->bottom); X LineTo(rp->left, n); X LineTo(m, rp->top); X break; X case 'h': /* hour glass */ X MoveTo(rp->left, rp->top); X LineTo(rp->right, rp->top); X LineTo(rp->left, rp->bottom); X LineTo(rp->right, rp->bottom); X LineTo(rp->left, rp->top); X break; X case 'x': X MoveTo(rp->left, rp->top); X LineTo(rp->right, rp->bottom); X MoveTo(rp->right, rp->top); X LineTo(rp->left, rp->bottom); X break; X case 'v': X MoveTo(rp->left, rp->top); X LineTo(m, rp->bottom); X LineTo(rp->right, rp->top); X break; X case '\\': X MoveTo(rp->left, rp->top); X LineTo(rp->right, rp->bottom); X break; X case '/': X MoveTo(rp->right, rp->top); X LineTo(rp->left, rp->bottom); X break; X case '+': X MoveTo(m, rp->top); X LineTo(m, rp->bottom); X MoveTo(rp->right, n); X LineTo(rp->left, n); X break; X } X} X/* X * change shape - redraw stuff in queue X */ XnewShape(s) X{ X register int x, n; X X if (s == shape) X return; X ObscureCursor(); X x = qHead; X n = nRinQ; X while (n-- > 0) { X frameShape(shape, &rQueue[x]); X frameShape(s, &rQueue[x]); X if (++x >= nQueue) X x = 0; X } X shape = s; X} X/* X * initialize stuff X */ XinitIdle(rp) XRect *rp; X{ X shape = 'o'; X limit = 0; X quantize = 0; X nRinQ = 0; X qHead = 0; X qTail = 0; X qSize = qInit; X X x1[1] = newDelta(rp->right - rp->left); X x1[0] = ((long)rp->right << 16) + x1[1]; X y1[1] = newDelta(rp->bottom - rp->top); X y1[0] = ((long)rp->top << 16) + y1[1]; X X x2[1] = -newDelta(rp->right - rp->left); X x2[0] = ((long)rp->left << 16) + x2[1]; X y2[1] = -newDelta(rp->bottom - rp->top); X y2[0] = ((long)rp->bottom << 16) + y2[1]; X} X/* X * one step of the way... X */ XrunIdle(rp) XRect *rp; X{ X Point p1, p2; X X ObscureCursor(); X /* X * undraw stuff at the head - shorten if necessary X */ X while (nRinQ >= qSize) { X frameShape(shape, &rQueue[qHead]); X if (++qHead >= nQueue) X qHead = 0; X --nRinQ; X } X /* X * compute new rectangle X */ X p1.h = newPoint(x1, rp->left, rp->right); X p1.v = newPoint(y1, rp->top, rp->bottom); X p2.h = newPoint(x2, rp->left, rp->right); X p2.v = newPoint(y2, rp->top, rp->bottom); X /* X * add rectangle to queue X */ X Pt2Rect(p1, p2, &rQueue[qTail]); X frameShape(shape, &rQueue[qTail]); X if (++qTail >= nQueue) X qTail = 0; X ++nRinQ; X} X/* X * key events come here X */ XkeyIdle(c) X{ X switch (c) { X case '[': /* shorten */ X if ((qSize -= qIncr) < qIncr) X qSize = qIncr; X break; X case ']': /* lengthen */ X if ((qSize += qIncr) > nQueue) X qSize = nQueue; X break; X default: X newShape(c); X break; X case 'q': X quantize = !quantize; X break; X case '0': case '1': case '2': case '3': case '4': X case '5': case '6': case '7': case '8': case '9': X limit = (long)(c - '0') << 17; X break; X } X return 0; X} SHAR_EOF sed 's/^X//' << 'SHAR_EOF' > Poly.c X/* X * general polygon idle desk accessory X * X * bounce points with random speeds X * save in queue X * connect the dots... X * X * keyboard commands: X * X * 0-9 select # points in polygon (0 or 1 means 10) X * [ shorten queue X * ] lengthen queue X * q quantize point speed X */ X#include <hd20:lightspeed:mac:quickdraw.h> X X#define nQueue 100 /* max polygons in queue */ X#define qInit 20 /* initial queue size */ X#define qIncr 10 /* queue size increment */ X#define nPoints 10 /* max points per poly */ X#define pInit 4 /* initial # points */ X Xint quantize; /* quantize point deltas */ X/* X * bouncing points - 1st is value, 2nd is delta, each w/16 bit fraction X */ Xlong x[nPoints][2], X y[nPoints][2]; X/* X * polygon queue X */ Xint qHead, qTail, qSize, nPinQ, pSize; XPoint pQueue[nQueue][nPoints]; X/* X * compute new delta X */ Xlong XnewDelta(range) Xint range; X{ X register int r; X register long d; X X if ((r = Random()) < 0) X r = -r; X d = ((long)range << 16) / (r % range + 1); X if (quantize && (d = (d + 0x7FFFL) & ~0xFFFFL) == 0) X d = 0x10000L; X return d; X} X/* X * compute new point X */ XnewPoint(p, lo, hi) Xlong *p; Xint lo, hi; X{ X register int v; X X v = p[0] >> 16; X if (v < lo) { X v = lo; X p[1] = newDelta(hi - lo); X } X else if (v > hi) { X v = hi; X p[1] = -newDelta(hi - lo); X } X p[0] += p[1]; X return v; X} X/* X * connect the dots... X */ XdrawShape(n, p) Xregister int n; XPoint *p; X{ X MoveTo(p[0].h, p[0].v); X if (n == 2) X LineTo(p[1].h, p[1].v); X else while (--n >= 0) X LineTo(p[n].h, p[n].v); X} X/* X * initialize stuff X */ XinitIdle(rp) XRect *rp; X{ X register int i; X X nPinQ = 0; X qHead = 0; X qTail = 0; X qSize = qInit; X pSize = pInit; X X for (i = 0; i < nPoints; ++i) { X if (i & 1) { /* L->R */ X x[i][1] = newDelta(rp->right - rp->left); X x[i][0] = ((long)rp->left << 16) + x[i][1]; X } X else { /* R->L */ X x[i][1] = -newDelta(rp->right - rp->left); X x[i][0] = ((long)rp->right << 16) + x[i][1]; X } X if (i & 2) { /* T->B */ X y[i][1] = -newDelta(rp->bottom - rp->top); X y[i][0] = ((long)rp->bottom << 16) + y[i][1]; X } X else { /* B->T */ X y[i][1] = newDelta(rp->bottom - rp->top); X y[i][0] = ((long)rp->top << 16) + y[i][1]; X } X } X} X/* X * drawing routine X */ XrunIdle(rp) XRect *rp; X{ X register int i; X X ObscureCursor(); X /* X * undraw stuff at head of queue - shorten if necessary X */ X while (nPinQ >= qSize) { X drawShape(pSize, pQueue[qHead]); X if (++qHead >= nQueue) X qHead = 0; X --nPinQ; X } X /* X * compute next set of points X */ X for (i = 0; i < nPoints; ++i) { X pQueue[qTail][i].h = newPoint(x[i], rp->left, rp->right); X pQueue[qTail][i].v = newPoint(y[i], rp->top, rp->bottom); X } X /* X * draw newest polygon X */ X drawShape(pSize, pQueue[qTail]); X if (++qTail >= nQueue) X qTail = 0; X ++nPinQ; X} X/* X * key events come here X */ XkeyIdle(c) X{ X switch (c) { X case '[': /* shorten */ X if ((qSize -= qIncr) < qIncr) X qSize = qIncr; X break; X case ']': /* lengthen */ X if ((qSize += qIncr) > nQueue) X qSize = nQueue; X break; X case 'q': X quantize = !quantize; X break; X case '1': case '0': X c = 10; X goto newSize; X case '2': case '3': case '4': case '5': X case '6': case '7': case '8': case '9': X c -= '0'; X newSize: X ObscureCursor(); X while (nPinQ > 0) { X drawShape(pSize, pQueue[qHead]); X if (++qHead >= nQueue) X qHead = 0; X --nPinQ; X } X pSize = c; X break; X } X} SHAR_EOF exit ---