1 /************************************************************************
2 * Version 1.00 TREE.C - Draw a Recursive Tree 08-May-86 *
3 * Commodore Amiga Only Module TREE.C *
4 *************************************************************************
5 * Copyright (c) 1986, Robert S. French *
6 * --------------------------------------------------------------------- *
7 * This program has been placed in the public domain. A limited *
8 * license is hereby granted for the unlimited use and distribution of *
9 * this program, provided it is not used for commercial or profit- *
10 * making purposes. Thank you. *
11 *************************************************************************
12 * Author information: | Disclaimer: *
14 * Name: Robert S. French | The author takes no responsibil- *
15 * USnail: 2740 Frankfort Avenue | ity for damages incurred during *
16 * Louisville, KY 40206 | the use of this program. *
17 * Phone: (502) 897-5096 \-----------------------------------*
18 * ARPA: French#Robert%d@LLL-MFE UUCP: ihnp4!ptsfa!well!french *
19 *************************************************************************
20 * Please send any comments, suggestions, or bugs to one of the above *
22 *************************************************************************
26 * Original version presented for IBM BASIC by William K. Balthrop in *
27 * Home Computer Magazine, Vol. 5, No. 6. *
29 * Random number generator from the Encyclopedia of Computer Science *
30 * and Engineering, second edition. *
31 ************************************************************************/
33 /* Necessary includes */
35 #include <aros/oldprograms.h>
37 #include <exec/types.h>
38 #include <exec/libraries.h>
39 #include <devices/keymap.h>
40 #include <graphics/copper.h>
42 #include <graphics/display.h>
44 #include <graphics/gfxbase.h>
45 #include <graphics/text.h>
46 #include <graphics/view.h>
47 #include <graphics/gels.h>
48 #include <graphics/regions.h>
49 #include <hardware/blit.h>
50 #include <intuition/intuition.h>
51 #include <intuition/intuitionbase.h>
58 /* Function Prototypes */
63 void drawbranch(int x
,int y
,int ex
,int ey
,int d
,int l
);
64 void branch(int xs
,int ys
,int len
,int dir
,int rl
);
67 /* Library Pointers */
69 struct IntuitionBase
*IntuitionBase
= 0;
70 struct GfxBase
*GfxBase
= 0;
72 /* Initial Graphics Conditions */
74 struct NewScreen newscr
= {
82 HIRES
, /* View Modes */
83 CUSTOMSCREEN
, /* Type */
85 "Recursive Tree (1.00) by Robert French - Right mouse button to exit", /* Title */
90 struct NewWindow newwin
= {
97 MOUSEBUTTONS
, /* IDCMP */
98 BACKDROP
| BORDERLESS
| ACTIVATE
| RMBTRAP
, /* Flags */
108 CUSTOMSCREEN
/* Screen type */
112 0x000, 0xfff, 0xf00, 0xff0, 0x0d0, 0x0b0, 0x090, 0xa84,
113 0x973, 0x970, 0x960, 0x860, 0x850, 0x750, 0x740, 0x640
116 struct Screen
*scr
= 0;
117 struct Window
*win
= 0;
121 /* Random Number Definitions */
124 int seedp1
,seedp2
,seedp3
;
126 /* Direction Definitions */
151 if ((IntuitionBase
= (struct IntuitionBase
*)OpenLibrary("intuition.library",0)) == 0)
152 abort("Can't open intuition.library");
154 if ((GfxBase
= (struct GfxBase
*)OpenLibrary("graphics.library",0)) == 0)
155 abort("Can't open graphics.library");
157 if ((scr
= (struct Screen
*)OpenScreen(&newscr
)) == 0)
158 abort("Can't open screen");
162 if ((win
= (struct Window
*)OpenWindow(&newwin
)) == 0)
163 abort("Can't open window");
168 LoadRGB4(vp
,colors
,16);
174 RectFill(rp
,0,10,639,199);
178 branch(320,120,14,0,1); /* Draw first right branch */
179 branch(320,120,14,0,-1); /* Draw first left branch */
197 CloseLibrary((struct Library
*)IntuitionBase
);
199 CloseLibrary((struct Library
*)GfxBase
);
204 void branch(xs
,ys
,len
,dir
,rl
)
205 int xs
,ys
,len
,dir
,rl
;
239 xe
= xs
+len
*offset
[dir
].x
;
240 ye
= ys
+len
*offset
[dir
].y
;
256 drawbranch(xs
,ys
,xe
,ye
,dir
,len
);
259 branch(xe
,ye
,len
,dir
,1); /* Draw right branch */
260 branch(xe
,ye
,len
,dir
,-1); /* Draw left branch */
263 void drawbranch(x
,y
,ex
,ey
,d
,l
)
269 Move(rp
,x
+boff
[d
&3].x
,y
+boff
[d
&3].y
);
270 Draw(rp
,ex
+boff
[d
&3].x
,ey
+boff
[d
&3].y
);
273 Move(rp
,x
-boff
[d
&3].x
,y
-boff
[d
&3].y
);
274 Draw(rp
,ex
-boff
[d
&3].x
,ey
-boff
[d
&3].y
);
285 CurrentTime(&sec
,&mic
);
303 result
= seeds
[seedp1
]+seeds
[seedp2
];
304 seeds
[seedp3
] = result
;
312 return (result
& 31);
320 RectFill(rp
,0,194,639,199);
326 for (i
=0;i
<c
;i
++,y
--) {
339 struct IntuiMessage
*message
;
343 while ((message
= (struct IntuiMessage
*)GetMsg(win
->UserPort
))) {
344 class = message
->Class
;
345 code
= message
->Code
;
346 ReplyMsg((struct Message
*)message
);
347 if (class == MOUSEBUTTONS
&& code
== MENUDOWN
)