1 /* frac.c 2.1 9004?? 946 lines */
3 #define NTSC_HEIGHT 200
5 #define TV_SYSTEM PAL_HEIGHT
6 /* This define tells the computer what TV_system you use, if you live in
7 europe, you probably have PAL and this definition is ok.
8 If you live in north america you will have to change the definition
9 to NTSC_HEIGHT. ( unless of course you have an european amiga and
13 #include <aros/oldprograms.h>
17 #include <exec/types.h>
18 #include <intuition/intuition.h>
20 #define SCREENTITLE "Fractals v 2.1 Ronnie J"
21 /* for Writeilbmfile */
27 short height
=TV_SYSTEM
;
29 static unsigned short viewmode
=0;
32 extern struct Gadget gad
[];
33 extern struct Gadget gadb
[];
34 extern char namebuf
[];
35 extern char nameundo
[];
38 extern struct MenuItem mit
[];
39 extern struct Menu men
[];
41 static short fracmenu
=0;
43 short xc
,yc
,xoffset
,yoffset
;
45 struct IntuitionBase
*IntuitionBase
;
46 struct GfxBase
*GfxBase
;
47 struct Screen
*scr
,*openscreen();
48 struct Window
*gwdw
,*wdw
,*openwindow();
49 struct IntuiMessage
*imsg
;
52 void ColorWindow(),scanmenu(),newscreen();
53 void ShutDown(),SavePic(),PutBoolGadget(),PutGadget();
57 short tmpcol
,mennum
,itmnum
,subnum
;
60 void runfractal(),run1fractal();
61 void getfractal(),get1fractal();
62 void switchrun(),switchfrac();
64 /* functions in file formulas2.c */
68 double sqrt(),atan(),log(),atof(),exp(),sin(),cos(),fabs();
70 struct RastPort
*rport
;
73 int main(int argc
, char **argv
)
76 IntuitionBase
=(struct IntuitionBase
*)OpenLibrary("intuition.library",0L);
77 if(IntuitionBase
==NULL
){printf("Error opening intuition!\n");ShutDown();};
79 GfxBase
=(struct GfxBase
*)OpenLibrary("graphics.library",0L);
80 if(GfxBase
==NULL
){printf("Error opening graphics!\n");ShutDown();};
82 scr
=openscreen(width
,height
,5,0);
83 if(scr
==NULL
){printf("Error opening screen!\n");ShutDown();};
85 wdw
=openwindow(scr
,0,0,scr
->Width
,scr
->Height
,
86 (ULONG
)(ACTIVATE
|SMART_REFRESH
|NOCAREREFRESH
|BACKDROP
|BORDERLESS
),
88 if(wdw
==NULL
){printf("Error opening window!\n");ShutDown();};
90 WVP
=(struct ViewPort
*)ViewPortAddress(wdw
);
91 SetRGB4(WVP
,0L,0L,0L,0L);
92 SetRGB4(WVP
,1L,15L,15L,15L);
98 SetMenuStrip(wdw
,menptr
);
99 Wait(1L << wdw
->UserPort
->mp_SigBit
);
101 while((imsg
=(struct IntuiMessage
*)GetMsg(wdw
->UserPort
)))
105 ReplyMsg((struct Message
*)imsg
);
108 mennum
=MENUNUM(code
);itmnum
=ITEMNUM(code
);subnum
=SUBNUM(code
);
111 if(itmnum
==ABOUT
)about();
112 if(itmnum
==TITLE
)toggletitle();
113 if(itmnum
==START
)switchrun();
114 if(itmnum
==COLOR
)ColorWindow(scr
);
115 if(itmnum
==SAVE
)SavePic();
119 if(itmnum
==NEXT
)newmenu();
120 if(itmnum
!=NEXT
)switchfrac();
122 if(mennum
==MENU2
)newscreen();
123 if(mennum
==MENU3
)surface
=itmnum
;
127 while((mennum
!=MENU0
)||(itmnum
!=QUIT
));
129 if(wdw
) CloseWindow(wdw
);
130 if(scr
) CloseScreen(scr
);
131 if(GfxBase
) CloseLibrary((struct Library
*)GfxBase
);
132 if(IntuitionBase
)CloseLibrary((struct Library
*)IntuitionBase
);
138 if(itmnum
==LO
)width
=320;
139 if(itmnum
==HI
)width
=640;
140 if(itmnum
==NO
)height
=TV_SYSTEM
;
141 if(itmnum
==LA
)height
=2*TV_SYSTEM
;
143 if(height
>300) viewmode
|= LACE
;
144 if(width
==640){ viewmode
|= HIRES
; depth
=4; };
146 if(wdw
)CloseWindow(wdw
);
147 if(scr
)CloseScreen(scr
);
149 scr
=openscreen(width
,height
,depth
,viewmode
);
152 wdw
=openwindow(scr
,0,0,scr
->Width
,scr
->Height
,
153 (ULONG
)(ACTIVATE
|SMART_REFRESH
|NOCAREREFRESH
|BACKDROP
|BORDERLESS
),
156 if((scr
==NULL
)||(wdw
==NULL
))
158 if(scr
)CloseScreen(scr
);
160 mit
[7].Flags
=CHECKED
|CHECKIT
|ITEMTEXT
|HIGHBOX
|ITEMENABLED
;
161 mit
[8].Flags
=CHECKIT
|ITEMTEXT
|HIGHBOX
|ITEMENABLED
;
162 mit
[9].Flags
=CHECKED
|CHECKIT
|ITEMTEXT
|HIGHBOX
|ITEMENABLED
;
163 mit
[10].Flags
=CHECKIT
|ITEMTEXT
|HIGHBOX
|ITEMENABLED
;
164 viewmode
=0;width
=320;height
=TV_SYSTEM
;depth
=5;
166 scr
=openscreen(width
,height
,depth
,viewmode
);
167 if(scr
==NULL
){printf("Error opening screen!\n");ShutDown();};
169 wdw
=openwindow(scr
,0,0,scr
->Width
,scr
->Height
,
170 (ULONG
)(ACTIVATE
|SMART_REFRESH
|NOCAREREFRESH
|BACKDROP
|BORDERLESS
),
172 if(wdw
==NULL
){printf("Error opening window!\n");ShutDown();};
175 WVP
=(struct ViewPort
*)ViewPortAddress(wdw
);
176 SetRGB4(WVP
,0L,0L,0L,0L);
177 SetRGB4(WVP
,1L,15L,15L,15L);
180 struct Window
*openwindow(scr
,left
,top
,width
,height
,flags
,idcmp
)
182 SHORT left
,top
,width
,height
;
186 struct NewWindow nwdw
;
195 nwdw
.IDCMPFlags
=idcmp
;
196 nwdw
.Type
=CUSTOMSCREEN
;
197 nwdw
.FirstGadget
=NULL
;
205 return(OpenWindow(&nwdw
));
211 titelflag
=1-titelflag
;
212 ShowTitle(scr
,titelflag
);
219 while((imsg
=(struct IntuiMessage
*)GetMsg(wdw
->UserPort
)))
223 ReplyMsg((struct Message
*)imsg
);
226 mennum
=MENUNUM(code
);itmnum
=ITEMNUM(code
);subnum
=SUBNUM(code
);
231 case 0: {xc
=xoffset
=width
;yc
=yoffset
=height
;break;};
232 case 1: {ClearMenuStrip(wdw
);ColorWindow(scr
);
233 SetMenuStrip(wdw
,(men
+3));break;};
234 case 2: {toggletitle();break;};
242 void PutGadget(text
,chrs
,xpos
,ypos
,gadptr
)
244 short chrs
,xpos
,ypos
;
245 struct Gadget
*gadptr
;
247 Move(rport
,(long)xpos
,(long)ypos
);
249 Text(rport
,text
,(long)chrs
);
250 RectFill(rport
,(long)(xpos
-1),(long)(ypos
-1),
251 (long)(xpos
+(*gadptr
).Width
-9),(long)(ypos
+(*gadptr
).Height
-1));
252 (*gadptr
).LeftEdge
=xpos
;
253 (*gadptr
).TopEdge
=ypos
;
254 AddGadget(gwdw
,gadptr
,0L);
257 void PutBoolGadget(xpos
,ypos
,gadptr
)
259 struct Gadget
*gadptr
;
261 RectFill(rport
,(long)(xpos
),(long)(ypos
),
262 (long)(xpos
+(*gadptr
).Width
),(long)(ypos
+(*gadptr
).Height
));
263 (*gadptr
).LeftEdge
=xpos
;
264 (*gadptr
).TopEdge
=ypos
;
265 AddGadget(gwdw
,gadptr
,0L);
266 RefreshGadgets(gadptr
,gwdw
,NULL
);
269 struct Screen
*openscreen(width
,height
,depth
,viewmodes
)
270 short width
,height
,depth
;
271 unsigned short viewmodes
;
273 struct NewScreen nscr
;
281 nscr
.ViewModes
=viewmodes
;
282 nscr
.Type
=CUSTOMSCREEN
;
284 nscr
.DefaultTitle
=(UBYTE
*)SCREENTITLE
;
286 nscr
.CustomBitMap
=NULL
;
287 return(OpenScreen(&nscr
));
292 gwdw
=openwindow(scr
,50,15,200,170,(ULONG
)ACTIVATE
,(USHORT
)GADGETUP
,NULL
);
295 Move(rport
,65L,10L);Text(rport
,"FRACTALS",8L);
296 Move(rport
,10L,30L);Text(rport
,"By Ronnie Johansson",19L);
297 Move(rport
,10L,40L);Text(rport
,"student of Mathematics",22L);
298 Move(rport
,10L,50L);Text(rport
,"University of Linkoping",23L);
299 Move(rport
,10L,70L);Text(rport
,"If you want to contact",22L);
300 Move(rport
,10L,80L);Text(rport
,"me, my address is :",19L);
301 Move(rport
,10L,90L);Text(rport
,"Hasselkulleg. 70",16L);
302 Move(rport
,10L,100L);Text(rport
,"461 62 TROLLHATTAN",18L);
303 Move(rport
,10L,110L);Text(rport
," SWEDEN",18L);
305 PutBoolGadget(110,130,(gadb
+0));
307 Wait(1L << gwdw
->UserPort
->mp_SigBit
);
308 while((imsg
=(struct IntuiMessage
*)GetMsg(gwdw
->UserPort
)))
309 ReplyMsg((struct Message
*)imsg
);
319 gwdw
=openwindow(scr
,50,50,150,100,(ULONG
)ACTIVATE
,
320 (USHORT
)(GADGETUP
),NULL
);
323 Move(rport
,10L,10L);Text(rport
,"SAVE - Fractal",14L);
324 PutGadget("Name",4,10,30,(gad
+15));
326 PutBoolGadget(10,70,(gadb
+1));
327 PutBoolGadget(90,70,(gadb
+2));
329 Wait(1L << gwdw
->UserPort
->mp_SigBit
);
330 while((imsg
=(struct IntuiMessage
*)GetMsg(gwdw
->UserPort
)))
332 if((((struct Gadget
*)(imsg
->IAddress
))->GadgetID
)==2)saveflag
=1;
333 ReplyMsg((struct Message
*)imsg
);
338 ShowTitle(scr
,titelflag
=0L);
339 success
=WriteILBMFile(namebuf
,scr
);
340 ShowTitle(scr
,titelflag
=1L);
342 /* Print result window */
343 gwdw
=openwindow(scr
,50,50,150,100,(ULONG
)ACTIVATE
,
344 (USHORT
)(GADGETUP
),NULL
);
349 { Text(rport
,"Picture saved.",14L); };
351 { Text(rport
,"Error :",7L); Move(rport
,10L,20L);
352 Text(rport
,"Saving file.",12L); Move(rport
,10L,30L);
353 Text(rport
,"File removed...",15L); };
355 { Text(rport
,"Error :",7L); Move(rport
,10L,20L);
356 Text(rport
,"Opening file.",13L); Move(rport
,10L,30L);
357 Text(rport
,"File not saved.",15L); };
358 PutBoolGadget(90,70,(gadb
+0));
360 Wait(1L << gwdw
->UserPort
->mp_SigBit
);
361 while((imsg
=(struct IntuiMessage
*)GetMsg(gwdw
->UserPort
)))
362 ReplyMsg((struct Message
*)imsg
);
369 if(wdw
) CloseWindow(wdw
);
370 if(scr
) CloseScreen(scr
);
371 if(GfxBase
) CloseLibrary((struct Library
*)GfxBase
);
372 if(IntuitionBase
)CloseLibrary((struct Library
*)IntuitionBase
);
381 case 0: { menptr
=(men
+5);
383 case 1: { menptr
=(men
+0);
388 if(fracmenu
>1)fracmenu
=0;
394 /* All algorithms can not use the standard plotting routines
395 ,therefore we use switch to call appropriate function.
399 case 0: { runfractal();break; };
400 case 1: { run1fractal();break; };
407 /* All frac menues have their own getfrac menu
411 case 0: { getfractal();break; };
412 case 1: { get1fractal();break; };