home *** CD-ROM | disk | FTP | other *** search
- /*
- This program is called Line Art. It draws pretty lines on the
- screen like the Early suns used to do.
-
- This is not my idea, but the implementation is.
-
- lineart -t - This leaves a trail (one out of every 'l' lines) remains
- on the screen.
- -n - This is the 'nice' option, this makes LineArt much more
- friendly in a multitasking environment (It takes less
- CPU time.)
- -cXXXX - This switch allows you to specify the initial color that
- the program will cycle from. Suggested color values start
- from 1500 (decimal) and up.
- -lXXXX - This switch allows you to specify the number of lines to
- be drawn before the last one is erased.
- -b - draw boxes (4 connected lines) instead of lines.
- nnn - This is an integer between 1 and 9 that will change the
- minimum distance between sucessive endpoints for each
- line drawn. A high number will give the illusion of
- unbelievable speed!
-
- The defaults (if you just type 'lineart') are as if you entered:
-
- LineArt 3 -t20 -c1280 -l10
-
- This program is PD. Use it or abuse it, only you will know.
-
- Steve -Raz- Berry
- A-7 Sinai Circle
- Chelmsford, Ma. 01824
-
- This program is a product of The Checkered Ball 1989.
-
- 2/19/89
-
- */
-
- #define NORMALFLAGS BORDERLESS|SMART_REFRESH|BACKDROP
-
- struct NewScreen scr = {
- 0,0, /* x,y start */
- 640,400, /* width, height */
- 1, /* depth */
- 2,1, /* detail, block pens */
- HIRES|LACE, /* view mode */
- CUSTOMSCREEN, /* screen type */
- NULL, /* font */
- NULL, /* title */
- NULL, /* gadgets */
- NULL /* bitmap pntr */
- };
-
- struct NewWindow mywin = {
- 0,0, /* x,y start */
- 640,400, /* width, height */
- 2,1, /* detail, block pens */
- VANILLAKEY | REFRESHWINDOW | GADGETDOWN | GADGETUP |
- /* IDCMP flags */
- MOUSEBUTTONS | REQCLEAR | SELECTDOWN | SELECTUP,
- NORMALFLAGS, /* window flags */
- NULL, NULL, /* pntr gadget, checkmark */
- NULL, /* title */
- NULL, /* screen pointer filled in later (run time) */
- NULL, /* bitmap pntr */
- 0, 0, 8000, 8000, /* default x,y, &size */
- CUSTOMSCREEN
- };
-
- UWORD coltbl[2] = {
- 0x000, /* background color */
- 0x500
- };
-
- LONG GfxBase, IntuitionBase;
-
- struct Window *win;
- struct RastPort *rp;
- struct ViewPort *vp;
- struct Screen *scrptr;
-
- long Enable_Abort = 0;
- long _stack = 10000, _priority = -11, _BackGroundIO = 1;
- char *_procname = "Line-Art";
-
- int scale1, scale2;
- long input, maxlines, ctemp;
-
- #define MAXLINES 1000
-
- long point1[MAXLINES+1][2], point2[MAXLINES+1][2], direction[2][2];
-
- main(argc,argv)
- int argc;
- char *argv[];
- {
- int i, count, trails, nice, boxes;
- register int offset, newoffset, tempx, tempy;
- struct IntuiMsg *msg;
-
- input = 3; /* Some defaults for switches */
- trails = 1;
- maxlines = 10;
- nice = FALSE;
- boxes = FALSE;
-
- while(--argc >= 1) {
- switch (argv[argc][0]) {
- case '-':
- switch (argv[argc][1]) {
- case 't':
- trails = 0;
- break;
- case 'n':
- nice = TRUE;
- break;
- case 'l':
- sscanf(&argv[argc][2],"%d",&maxlines);
- maxlines = (maxlines > MAXLINES) ? MAXLINES : (maxlines < 1) ? 1 : maxlines;
- break;
- case 'c':
- sscanf(&argv[argc][2],"%d",&ctemp);
- coltbl[1] = (ctemp > 4096) ? 4096 : (ctemp < 1) ? 1 : ctemp;
- break;
- case 'b':
- boxes = TRUE;
- break;
- default:
- exit(20);
- }
- break;
- default:
- sscanf(argv[argc],"%d",&input);
- break;
- }
- }
-
- input = (input > 9) ? 9 : (input < 0) ? 1 : input;
-
- openstuff();
-
- Enable_Abort = 1;
- for(i=0;i<VBeamPos();i++)
- get_rand_point();
-
- point1[0][0] = get_rand_point(); /* Initial start x,y (one endpoint) */
- point1[0][1] = get_rand_point();
-
- point2[0][0] = get_rand_point();
- point2[0][1] = get_rand_point();
-
- for(i=0;i<2;i++){
- direction[i][0] = get_rand_dir();
- direction[i][1] = get_rand_dir();
- }
-
- offset = 0;
- count = 0;
- scale1 = 2;
- scale2 = 2;
-
- rp = win->RPort;
- SetAPen(rp, 1L);
-
- while(1){
-
- Chk_Abort();
-
- if (nice)
- WaitTOF();
-
- msg = GetMsg(win->UserPort);
- if (msg == NULL) {
-
- Move(rp, point1[offset][0], point1[offset][1]);
- Draw(rp, point2[offset][0], point2[offset][1]);
-
- if (boxes) {
- dobox(offset);
- }
-
- if (checkbounce1(offset)) {
-
- tempx = direction[0][0];
- tempy = direction[0][1];
-
- direction[0][0] = (tempx == -1 & point1[offset][0] < 10) ? 1 :
- (tempx == 1 & point1[offset][0] > 630) ? -1 : get_rand_dir();
-
- direction[0][1] = (tempy == -1 & point1[offset][1] < 10) ? 1 :
- (tempy == 1 & point1[offset][1] > 390) ? -1 : get_rand_dir();
-
- scale1 = get_rand_scale();
- }
-
- if (checkbounce2(offset)) {
-
- tempx = direction[1][0];
- tempy = direction[1][1];
-
- direction[1][0] = (tempx == -1 & point2[offset][0] < 10) ? 1 :
- (tempx == 1 & point2[offset][0] > 630) ? -1 : get_rand_dir();
-
- direction[1][1] = (tempy == -1 & point2[offset][1] < 10) ? 1 :
- (tempy == 1 & point2[offset][1] > 390) ? -1 : get_rand_dir();
-
- scale2 = get_rand_scale();
- }
-
- if (++count > 60000) {
- count = maxlines;
- if (trails == 0) {
- Move(rp, 0, 0);
- ClearScreen(rp);
- }
- }
-
- if (++offset > maxlines){
- LoadRGB4(vp,coltbl,2L);
- if (coltbl[1] == 0xfff)
- coltbl[1] = ctemp;
- else
- *coltbl[1]++;
- offset = 0;
- }
-
- /* Erase the oldest line... */
-
- if (count > maxlines-1) {
-
- newoffset = (offset == maxlines) ? 0 : offset + trails;
- SetAPen(rp, 0L);
- Move(rp, point1[newoffset][0], point1[newoffset][1]);
- Draw(rp, point2[newoffset][0], point2[newoffset][1]);
-
- if (boxes) {
- dobox(newoffset);
- }
-
- SetAPen(rp, 1L);
- }
-
- /* Calculate the next point */
-
- newoffset = (offset > 0) ? offset-1 : maxlines;
- point1[offset][0] = scale1 * direction[0][0] + point1[newoffset][0];
- point1[offset][1] = scale1 * direction[0][1] + point1[newoffset][1];
-
- point2[offset][0] = scale2 * direction[1][0] + point2[newoffset][0];
- point2[offset][1] = scale2 * direction[1][1] + point2[newoffset][1];
-
- }
- else {
- ReplyMsg(msg);
- msg = GetMsg(win->UserPort);
- while (msg != NULL) {
- ReplyMsg(msg);
- msg = GetMsg(win->UserPort);
- }
- break;
- }
- }
- _abort:
- CloseWindow(win);
- CloseScreen(scrptr);
- CloseLibrary(GfxBase);
- CloseLibrary(IntuitionBase);
- }
-
- openstuff()
- {
- GfxBase = OpenLibrary("graphics.library",0L);
- if (GfxBase == NULL) {
- exit(100);
- }
-
- IntuitionBase = OpenLibrary("intuition.library",0L);
- if (IntuitionBase == NULL) {
- exit(50);
- }
-
- scrptr = OpenScreen(&scr);
- if (scrptr == NULL) {
- exit(30L);
- }
-
- mywin.Screen = scrptr;
- win = OpenWindow(&mywin);
- if (win == NULL) {
- CloseScreen(scrptr);
- exit(20);
- }
-
- ShowTitle(scrptr, FALSE);
- vp = &scrptr->ViewPort;
-
- LoadRGB4(vp,coltbl,2L);
-
- }
-
- dobox(offset)
- register int offset;
- {
- register int tempx, tempy;
-
- tempx = 640 - point1[offset][0];
- tempy = 400 - point1[offset][1];
- Draw(rp, tempx, tempy);
-
- tempx = 640 - point2[offset][0];
- tempy = 400 - point2[offset][1];
- Draw(rp, tempx, tempy);
-
- Draw(rp, point1[offset][0], point1[offset][1]);
- }
-
- long checkbounce1(index)
- register int index;
- {
-
- return (point1[index][0] > 630) | (point1[index][1] > 390) |
- (point1[index][0] < 10) | (point1[index][1] < 10);
- }
-
- long checkbounce2(index)
- register int index;
- {
- return (point2[index][0] > 630) | (point2[index][1] > 390) |
- (point2[index][0] < 10) | (point2[index][1] < 10);
- }
-
- int get_rand_point()
- {
- register short temp;
-
- temp = ran();
- if (temp < 0)
- temp = temp * -1;
- temp = temp/319+20;
-
- return temp;
- }
-
- int get_rand_dir()
- {
- register short num;
-
- num = ran((short)3);
-
- return (num < -5000) ? -1 : (num > 5000) ? 1 : 0;
- }
-
- int get_rand_scale()
- {
- register short temp;
-
- temp = ran();
- if (temp < 0)
- temp = temp * -1;
- temp = temp/6560 + (short)input;
-
- return temp;
- }
-