2 * lines.c : Line pattern generator experimental interface
4 * this stuf adapted from mackie.c on fish disk 131.
5 * by Joel Swank 11-13-88
13 * The maximum number of lines on the screen at once.
16 #include <aros/oldprograms.h>
17 #include <exec/types.h>
18 #include <intuition/intuition.h>
23 #define MAXLINES (100)
29 #define INTUITION_REV 1L
32 * The global variables.
34 struct GfxBase
*GfxBase
;
35 struct RastPort
*rastport
;
36 int screenheight
, screenwidth
;
38 struct Window
*Wind
= NULL
;
39 struct MsgPort
*CreatePort() ;
40 struct IntuitionBase
*IntuitionBase
;
41 struct IntuiMessage
*msg
;
46 * definition of the main window
49 static struct NewWindow New_Window
= {
50 0, 2, /* Take all except the */
51 XSIZE
, YSIZE
, /* top two lines */
52 -1, -1, /* Default pens */
53 CLOSEWINDOW
+VANILLAKEY
, /* Inputs acceppeted */
54 WINDOWCLOSE
/* Fairly standard window */
55 | BACKDROP
| SIMPLE_REFRESH
| BORDERLESS
,
56 NULL
, /* no gadgets */
57 (struct Image
*) NULL
,
58 (UBYTE
*) "h for Help", /* title */
59 (struct Screen
*) NULL
, /* filled at startup */
60 (struct BitMap
*) NULL
,
61 0, 0, 0, 0, /* no change sizes, doesn't matter */
68 static struct NewScreen newscreen
= {
73 HIRES
| LACE
| SCREENQUIET
,
80 char *HelpText
[40] = {
81 " Lines - line pattern generator",
82 " by Joel Swank 11/13/88",
84 " Control from keyboard as follows:",
86 " space Start/Stop generation",
87 " o Do one generation",
88 " f Freeze Thaw color rotation",
91 " Escape Exit Program",
93 " Return to continue",
107 int main(int argc
, char **argv
) {
109 USHORT keycode
, stop
, freeze
;
111 screenheight
= YSIZE
;
114 if ((IntuitionBase
= (struct IntuitionBase
*)
115 OpenLibrary("intuition.library", INTUITION_REV
)) == NULL
)
118 GfxBase
= (struct GfxBase
*)OpenLibrary("graphics.library", 0);
119 if (GfxBase
== NULL
) done(22);
121 if ( (scr
= OpenScreen(&newscreen
)) == NULL
) done(26);
122 New_Window
.Screen
= scr
;
124 if ((Wind
= (struct Window
*) OpenWindow(&New_Window
)) == NULL
)
126 rastport
= Wind
->RPort
;
128 SetRGB4(&(scr
->ViewPort
), 0L, 0L, 0L, 0L) ;
132 for (i
=0; i
<MAXLINES
; i
++) {
142 while(NULL
!= (msg
= (struct IntuiMessage
*) GetMsg(Wind
->UserPort
))) {
146 ReplyMsg((struct Message
*)msg
);
149 case ' ': /* start/stop */
150 if (stop
== TRUE
) stop
= FALSE
;
154 /* wait for this message */
155 if (!stop
) Wait( 1L << Wind
->UserPort
->mp_SigBit
);
157 /* wait on next mesg */
158 Wait( 1L << Wind
->UserPort
->mp_SigBit
);
161 case 'o': /* one iteration */
164 case 'f': /* freeze/thaw color changing */
165 if (freeze
== TRUE
) freeze
= FALSE
;
176 ReplyMsg((struct Message
*)msg
);
179 ReplyMsg((struct Message
*)msg
);
183 Wait( 1L << Wind
->UserPort
->mp_SigBit
); /* wait on mesg */
206 if (!freeze
) colors() ;
215 * done - just clean up that which is open, and then leave.
220 if (Wind
) CloseWindow(Wind
) ;
221 if (scr
) CloseScreen(scr
) ;
222 if (IntuitionBase
) CloseLibrary((struct Library
*)IntuitionBase
) ;
223 if (GfxBase
) CloseLibrary((struct Library
*)GfxBase
) ;
225 //OpenWorkBench() ; /* As requested */
230 * This routine returns a random value from 0 to n-1.
239 seed
= 323214521 + scr
->MouseX
+
241 seed
= seed
* 123213 + 121 ;
242 rval
= (seed
>> 5) & 65535 ;
243 return ((i
* rval
) >> 16) ;
246 * This routine sets x and y values to a random number.
250 x
= randm(screenwidth
) ;
251 y
= randm(screenheight
) ;
254 * Main routines are always fun.
256 short x1store
[MAXLINES
], y1store
[MAXLINES
] ;
257 short x2store
[MAXLINES
], y2store
[MAXLINES
] ;
259 short dx1
, dy1
, dx2
, dy2
;
260 short ox1
, oy1
, ox2
, oy2
;
261 short nx1
, ny1
, nx2
, ny2
;
266 * Initialize things for the first lines.
271 ox1
= randm(screenwidth
) ;
272 ox2
= randm(screenwidth
) ;
273 oy1
= randm(screenheight
) ;
274 oy2
= randm(screenheight
) ;
286 SetRGB4(&(scr
->ViewPort
), 0L, 0L, 0L, 0L) ;
287 SetRGB4(&(scr
->ViewPort
), 1L, (long)(nr
>> 3),
288 (long)(ng
>> 3), (long)(nb
>> 3)) ;
291 * Advance the number by the delta, and check the boundaries.
301 } else if (*n
>= w
) {
303 *d
= - randm(6) - 1 ;
307 * Advance the two points which make up the lines.
309 void advancelines() {
310 adv(&ox1
, &dx1
, &nx1
, screenwidth
) ;
311 adv(&ox2
, &dx2
, &nx2
, screenwidth
) ;
312 adv(&oy1
, &dy1
, &ny1
, screenheight
) ;
313 adv(&oy2
, &dy2
, &ny2
, screenheight
) ;
316 * Draw a new set of lines.
319 x1store
[ptr
] = ox1
= nx1
;
320 x2store
[ptr
] = ox2
= nx2
;
321 y1store
[ptr
] = oy1
= ny1
;
322 y2store
[ptr
] = oy2
= ny2
;
323 Move(rastport
, (long)ox1
, (long)oy1
) ;
324 Draw(rastport
, (long)ox2
, (long)oy2
) ;
325 Draw(rastport
, (long)(screenwidth
-ox1
-1), (long)(screenheight
-oy1
-1)) ;
326 Draw(rastport
, (long)(screenwidth
-ox2
-1), (long)(screenheight
-oy2
-1)) ;
327 Draw(rastport
, (long)ox1
, (long)oy1
) ;
333 * Erase the old line.
338 oldpen
= rastport
->FgPen
;
339 SetAPen(rastport
, 0L) ;
340 Move(rastport
, (long)x1store
[ptr
], (long)y1store
[ptr
]) ;
341 Draw(rastport
, (long)x2store
[ptr
], (long)y2store
[ptr
]) ;
342 Draw(rastport
, (long)(screenwidth
-x1store
[ptr
]-1),
343 (long)(screenheight
-y1store
[ptr
]-1)) ;
344 Draw(rastport
, (long)(screenwidth
-x2store
[ptr
]-1),
345 (long)(screenheight
-y2store
[ptr
]-1)) ;
346 Draw(rastport
, (long)x1store
[ptr
], (long)y1store
[ptr
]) ;
347 SetAPen(rastport
, (long)oldpen
) ;
350 * This routine mucks with the colors.
356 adv(&or, &dr
, &nr
, 128) ;
357 adv(&og
, &dg
, &ng
, 128) ;
358 adv(&ob
, &db
, &nb
, 128) ;
359 SetRGB4(&(scr
->ViewPort
), 1L, (long)(nr
>> 3),
360 (long)(ng
>> 3), (long)(nb
>> 3)) ;
364 * do_help - display help text
372 for (i
=0; i
<MAXHELP
; i
++) /* dump the whole help text array */
374 if (!HelpText
[i
]) break;
375 Move(rastport
,50L,(long) (i
+1)*9+20);
376 Text(rastport
,HelpText
[i
], (long) strlen(HelpText
[i
]));
384 SetAPen(rastport
, 0L) ;
386 RectFill(rastport
, 0L, 0L, (long)screenwidth
-1, (long)screenheight
-1) ;
388 SetAPen(rastport
, 1L) ;