Fix for the problem that SDL applications exited
[AROS-Contrib.git] / fish / henon / henon.c
blob2b14c7628e70b306b95878ff591428f1f937dee2
1 /* Hénon v1.10
2 * A program for drawing Hénon pictures.
3 * Written by Stefan Zeiger in May '91
4 * Updated 2/1992
5 * © 1992 by ! Wizard Works !
6 * Compiler : SAS/C 5.10
7 */
10 #include <exec/types.h>
11 #include <graphics/gfxbase.h>
12 #include <graphics/gfx.h>
13 #include <intuition/intuitionbase.h>
14 #include <intuition/intuition.h>
15 #include <intuition/iobsolete.h>
16 #include <proto/exec.h>
17 #include <proto/dos.h>
18 #include <proto/intuition.h>
19 #include <proto/graphics.h>
20 #include <proto/mathieeedoubtrans.h>
21 #include <stdio.h>
22 #include <string.h>
23 #include <math.h>
25 #ifndef TOPAZ_EIGHTY
26 #define TOPAZ_EIGHTY 8
27 #endif
29 int CXBRK(void) { return(0); } /* Disable Lattice CTRL-C handling */
30 int chkabort(void) { return(0); } /* really */
33 #define SIZE (80.0)
34 #define XSIZE (160.0)
37 struct IntuitionBase *IntuitionBase;
38 struct GfxBase *GfxBase=NULL;
39 struct Library * MathIeeeDoubTransBase = NULL;
42 struct Screen *my_screen=NULL;
43 struct NewScreen my_new_screen=
45 0, /* LeftEdge */
46 0, /* TopEdge */
47 640, /* Width */
48 200, /* Height */
49 2, /* Depth */
50 0, /* DetailPen */
51 1, /* BlockPen */
52 HIRES, /* ViewModes */
53 CUSTOMSCREEN, /* Type */
54 NULL, /* Font */
55 "Hénon v1.00", /* Title */
56 NULL, /* Gadget */
57 NULL /* BitMap */
61 struct Window *my_window=NULL;
62 struct NewWindow my_new_window=
64 0, /* LeftEdge */
65 11, /* TopEdge */
66 640, /* Width */
67 189, /* Height */
68 0, /* DetailPen */
69 1, /* BlockPen */
70 CLOSEWINDOW, /* IDCMPFlags */
71 /* */
72 SMART_REFRESH| /* Flags */
73 WINDOWCLOSE| /* */
74 ACTIVATE, /* */
75 NULL, /* FirstGadget */
76 NULL, /* CheckMark */
77 "The Hénon picture :",
78 NULL, /* Screen */
79 NULL, /* BitMap */
80 0, /* MinWidth */
81 0, /* MinHeight */
82 0, /* MaxWidth */
83 0, /* MaxHeight */
84 CUSTOMSCREEN /* Type */
88 struct TextAttr my_font=
90 "topaz.font",TOPAZ_EIGHTY,0,FPF_ROMFONT
93 struct IntuiText black_text=
95 1,0,JAM2,
96 0,0,
97 &my_font,
98 NULL, /* Text */
99 NULL
103 void cleanexit(void);
106 int main(int argc,char **argv)
108 unsigned char buf[20];
109 double xx,x,y,xa,a,xymin,xymax,xystep,cosinus,sinus,precalc;
110 ULONG i,class;
111 long itera;
112 BOOL close_me=FALSE;
113 struct IntuiMessage *my_message;
114 BOOL os2=TRUE;
115 UWORD PenData[]={~0};
117 /****** INTERPRET ARGUMENTS ******/
119 if(argc == 2)
121 if(strcmp(argv[1],"?")==0)
123 Write(Output(),"Hénon v1.00 by ! WIZARD WORKS !\nUsage : ",40);
124 Write(Output(),argv[0],strlen(argv[0]));
125 Write(Output()," <a> <xymin> <xymax> <xystep> <itera>\n",38);
126 cleanexit();
127 return RETURN_FAIL;
131 if(argc!=6)
133 puts("Bad args.");
134 cleanexit();
135 return RETURN_FAIL;
138 sscanf(argv[1],"%lf",&a);
139 sscanf(argv[2],"%lf",&xymin);
140 sscanf(argv[3],"%lf",&xymax);
141 sscanf(argv[4],"%lf",&xystep);
142 sscanf(argv[5],"%ld",&itera);
144 /****** PREPARE EVERYTHING ******/
146 IntuitionBase=(struct IntuitionBase *) OpenLibrary("intuition.library",37);
147 if(IntuitionBase==NULL)
149 IntuitionBase=(struct IntuitionBase *) OpenLibrary("intuition.library",0);
150 os2=FALSE;
151 if(IntuitionBase==NULL)
153 puts("Can't open Intuition !");
154 cleanexit();
155 return RETURN_FAIL;
159 GfxBase=(struct GfxBase *) OpenLibrary("graphics.library",0);
160 if(GfxBase==NULL)
162 puts("Can't open Graphics !");
163 cleanexit();
164 return RETURN_FAIL;
167 MathIeeeDoubTransBase=(struct Library *)
168 OpenLibrary("mathieeedoubtrans.library",0);
169 if(MathIeeeDoubTransBase==NULL)
171 puts("Can't open IEEE library !");
172 cleanexit();
173 return RETURN_FAIL;
176 if(os2)
177 my_screen=(struct Screen*) OpenScreenTags(&my_new_screen,SA_Pens,PenData,TAG_DONE,0);
178 else
179 my_screen=(struct Screen*) OpenScreen(&my_new_screen);
181 if(my_screen==NULL)
183 puts("Can't open Screen");
184 cleanexit();
185 return RETURN_FAIL;
188 my_new_window.Screen=my_screen;
189 my_window=(struct Window *) OpenWindow(&my_new_window);
190 if(my_window==NULL)
192 puts("Can't open Window");
193 cleanexit();
194 return RETURN_FAIL;
197 SetAPen(my_window->RPort,1);
198 black_text.IText=buf;
200 //cosinus=IEEEDPCos(a);
201 //sinus=IEEEDPSin(a);
202 cosinus = cos(a);
203 sinus=sin(a);
205 /****** DRAW PICTURE ******/
206 SetAPen(my_window->RPort,1);
208 for(xa=xymin;xa<=xymax;xa+=xystep)
210 x=xa;
211 y=xa;
213 for(i=0;i<=itera;i++)
215 precalc=y-(x*x);
216 xx=x*cosinus-precalc*sinus;
217 y=x*sinus+precalc*cosinus;
218 x=xx;
219 WritePixel(my_window->RPort,(ULONG)((XSIZE*x)+370.0),(ULONG)(105-(SIZE*y)));
221 my_message=(struct IntuiMessage *)GetMsg(my_window->UserPort);
222 if(my_message)
224 class=my_message->Class;
225 ReplyMsg((struct Message *)my_message);
226 if(class==CLOSEWINDOW) close_me=TRUE;
228 if(close_me==TRUE) break;
231 /****** PRINT INFO ******/
232 sprintf(buf,"A : %lf",a);
233 PrintIText(my_window->RPort,&black_text,8,15);
234 sprintf(buf,"XYMin : %lf",xymin);
235 PrintIText(my_window->RPort,&black_text,8,23);
236 sprintf(buf,"XYMax : %lf",xymax);
237 PrintIText(my_window->RPort,&black_text,8,31);
238 sprintf(buf,"XYStep : %lf",xystep);
239 PrintIText(my_window->RPort,&black_text,8,39);
240 sprintf(buf,"Itera : %ld",(long)itera);
241 PrintIText(my_window->RPort,&black_text,8,47);
243 /****** TERMINATE PROGRAM ******/
245 while(close_me==FALSE)
247 Wait(1<<my_window->UserPort->mp_SigBit);
248 my_message=(struct IntuiMessage *)GetMsg(my_window->UserPort);
249 if(my_message)
251 class=my_message->Class;
252 ReplyMsg((struct Message *)my_message);
253 if(class==CLOSEWINDOW)
254 close_me=TRUE;
258 cleanexit();
260 return RETURN_OK;
263 void cleanexit()
265 if(my_window) CloseWindow(my_window);
266 if(my_screen) CloseScreen(my_screen);
267 if(GfxBase) CloseLibrary((struct Library *)GfxBase);
268 if(IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);