Same fix as r45172 for classes/iconimage:
[AROS-Contrib.git] / fish / 371_fractal / frac.c
blobc2617cf708d1d2fba2fe1ea059f1075ae5f3580a
1 /* frac.c 2.1 9004?? 946 lines */
2 #define PAL_HEIGHT 256
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
10 european tv set. )
13 #include <aros/oldprograms.h>
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <math.h>
17 #include <exec/types.h>
18 #include <intuition/intuition.h>
19 #include "defs.h"
20 #define SCREENTITLE "Fractals v 2.1 Ronnie J"
21 /* for Writeilbmfile */
22 #define WSAVE 0L
23 #define NOSAVE 1L
24 #define NOOPEN 2L
26 short width=320;
27 short height=TV_SYSTEM;
28 short depth=5;
29 static unsigned short viewmode=0;
30 long titelflag=1L;
32 extern struct Gadget gad[];
33 extern struct Gadget gadb[];
34 extern char namebuf[];
35 extern char nameundo[];
37 /* Menues */
38 extern struct MenuItem mit[];
39 extern struct Menu men[];
40 struct Menu *menptr;
41 static short fracmenu=0;
42 short surface=D2RECT;
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;
50 struct ViewPort *WVP;
52 void ColorWindow(),scanmenu(),newscreen();
53 void ShutDown(),SavePic(),PutBoolGadget(),PutGadget();
54 void newmenu();
55 ULONG class;
56 USHORT code;
57 short tmpcol,mennum,itmnum,subnum;
58 long WriteILBMFile();
59 void about();
60 void runfractal(),run1fractal();
61 void getfractal(),get1fractal();
62 void switchrun(),switchfrac();
64 /* functions in file formulas2.c */
65 void stratt();
67 void toggletitle();
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),
87 (USHORT)MENUPICK);
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);
94 menptr=(men+0);
98 SetMenuStrip(wdw,menptr);
99 Wait(1L << wdw->UserPort->mp_SigBit);
100 ClearMenuStrip(wdw);
101 while((imsg=(struct IntuiMessage *)GetMsg(wdw->UserPort)))
103 class=imsg->Class;
104 code=imsg->Code;
105 ReplyMsg((struct Message *)imsg);
106 if(class==MENUPICK)
108 mennum=MENUNUM(code);itmnum=ITEMNUM(code);subnum=SUBNUM(code);
109 if(mennum==MENU0)
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();
117 if(mennum==MENU1)
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);
133 return 0;
136 void newscreen()
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;
142 depth=5;viewmode=0;
143 if(height>300) viewmode |= LACE;
144 if(width==640){ viewmode |= HIRES; depth=4; };
146 if(wdw)CloseWindow(wdw);
147 if(scr)CloseScreen(scr);
148 scr=NULL;wdw=NULL;
149 scr=openscreen(width,height,depth,viewmode);
150 if(scr!=NULL)
152 wdw=openwindow(scr,0,0,scr->Width,scr->Height,
153 (ULONG)(ACTIVATE|SMART_REFRESH|NOCAREREFRESH|BACKDROP|BORDERLESS),
154 (USHORT)MENUPICK);
156 if((scr==NULL)||(wdw==NULL))
158 if(scr)CloseScreen(scr);
159 scr=NULL;wdw=NULL;
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),
171 (USHORT)MENUPICK);
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)
181 struct Screen *scr;
182 SHORT left,top,width,height;
183 ULONG flags;
184 USHORT idcmp;
186 struct NewWindow nwdw;
187 nwdw.LeftEdge=left;
188 nwdw.TopEdge=top;
189 nwdw.Width=width;
190 nwdw.Height=height;
191 nwdw.DetailPen=0;
192 nwdw.BlockPen=1;
193 nwdw.Title=NULL;
194 nwdw.Flags=flags;
195 nwdw.IDCMPFlags=idcmp;
196 nwdw.Type=CUSTOMSCREEN;
197 nwdw.FirstGadget=NULL;
198 nwdw.CheckMark=NULL;
199 nwdw.Screen=scr;
200 nwdw.BitMap=NULL;
201 nwdw.MinWidth=0;
202 nwdw.MaxWidth=0;
203 nwdw.MinHeight=0;
204 nwdw.MaxHeight=0;
205 return(OpenWindow(&nwdw));
209 void toggletitle()
211 titelflag=1-titelflag;
212 ShowTitle(scr,titelflag);
217 void scanmenu()
219 while((imsg=(struct IntuiMessage *)GetMsg(wdw->UserPort)))
221 class=imsg->Class;
222 code=imsg->Code;
223 ReplyMsg((struct Message *)imsg);
224 if(class==MENUPICK)
226 mennum=MENUNUM(code);itmnum=ITEMNUM(code);subnum=SUBNUM(code);
227 if(mennum==MENU0)
229 switch(itmnum)
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)
243 UBYTE *text;
244 short chrs,xpos,ypos;
245 struct Gadget *gadptr;
247 Move(rport,(long)xpos,(long)ypos);
248 ypos+=5;
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)
258 short xpos,ypos;
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;
274 nscr.LeftEdge=0;
275 nscr.TopEdge=0;
276 nscr.Width=width;
277 nscr.Height=height;
278 nscr.Depth=depth;
279 nscr.DetailPen=0;
280 nscr.BlockPen=1;
281 nscr.ViewModes=viewmodes;
282 nscr.Type=CUSTOMSCREEN;
283 nscr.Font=NULL;
284 nscr.DefaultTitle=(UBYTE *)SCREENTITLE;
285 nscr.Gadgets=NULL;
286 nscr.CustomBitMap=NULL;
287 return(OpenScreen(&nscr));
290 void about()
292 gwdw=openwindow(scr,50,15,200,170,(ULONG)ACTIVATE,(USHORT)GADGETUP,NULL);
293 rport=gwdw->RPort;
294 SetAPen(rport,1L);
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);
310 CloseWindow(gwdw);
314 void SavePic()
316 long success;
317 char saveflag;
318 saveflag=0;
319 gwdw=openwindow(scr,50,50,150,100,(ULONG)ACTIVATE,
320 (USHORT)(GADGETUP),NULL);
321 rport=gwdw->RPort;
322 SetAPen(rport,1L);
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);
335 CloseWindow(gwdw);
336 if(saveflag==1)
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);
345 rport=gwdw->RPort;
346 SetAPen(rport,1L);
347 Move(rport,10L,10L);
348 if(success==WSAVE)
349 { Text(rport,"Picture saved.",14L); };
350 if(success==NOSAVE)
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); };
354 if(success==NOOPEN)
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));
359 ScreenToFront(scr);
360 Wait(1L << gwdw->UserPort->mp_SigBit);
361 while((imsg=(struct IntuiMessage *)GetMsg(gwdw->UserPort)))
362 ReplyMsg((struct Message *)imsg);
363 CloseWindow(gwdw);
367 void ShutDown()
369 if(wdw) CloseWindow(wdw);
370 if(scr) CloseScreen(scr);
371 if(GfxBase) CloseLibrary((struct Library *)GfxBase);
372 if(IntuitionBase)CloseLibrary((struct Library *)IntuitionBase);
373 exit(10);
377 void newmenu()
379 switch(fracmenu)
381 case 0: { menptr=(men+5);
382 break; };
383 case 1: { menptr=(men+0);
384 break; };
387 fracmenu++;
388 if(fracmenu>1)fracmenu=0;
392 void switchrun()
394 /* All algorithms can not use the standard plotting routines
395 ,therefore we use switch to call appropriate function.
397 switch(fracmenu)
399 case 0: { runfractal();break; };
400 case 1: { run1fractal();break; };
405 void switchfrac()
407 /* All frac menues have their own getfrac menu
409 switch(fracmenu)
411 case 0: { getfractal();break; };
412 case 1: { get1fractal();break; };