home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / dirs / fractals_371.lzh / Fractals / src / NTSCfrac.c < prev    next >
C/C++ Source or Header  |  1990-10-08  |  11KB  |  424 lines

  1. /* frac.c 2.0b 9004?? 946 lines */
  2. #define PAL_HEIGHT 256
  3. #define NTSC_HEIGHT 200
  4.  
  5. #define TV_SYSTEM NTSC_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. )
  11. */
  12.  
  13. #include <stdio.h>
  14. #include <math.h>
  15. #include <exec/types.h>
  16. #include <intuition/intuition.h>
  17. #include "defs.h"
  18. #define SCREENTITLE "Fractals v 2.1  Ronnie J"
  19. /* for Writeilbmfile */
  20. #define WSAVE 0L
  21. #define NOSAVE 1L
  22. #define NOOPEN 2L
  23.  
  24. short width=320;
  25. short height=TV_SYSTEM;
  26. short depth=5;
  27. static unsigned short viewmode=0;
  28. long titelflag=1L;
  29.  
  30. extern struct Gadget gad[];
  31. extern struct Gadget gadb[];
  32. extern char namebuf[];
  33. extern char nameundo[];
  34.  
  35. /* Menues */
  36. extern struct MenuItem mit[];
  37. extern struct Menu men[];
  38.        struct Menu *menptr;
  39. static short  fracmenu=0;
  40.        short surface=D2RECT;
  41.        short xc,yc,xoffset,yoffset;
  42.  
  43. struct IntuitionBase *IntuitionBase;
  44. struct GfxBase *GfxBase;
  45. struct Library *OpenLibrary();
  46. struct Screen *scr,*openscreen(),*OpenScreen();
  47. struct Window *gwdw,*wdw,*openwindow(),*OpenWindow();
  48. struct Message *GetMsg();
  49. struct IntuiMessage *imsg;
  50. struct View *ViewPortAddress();
  51. struct ViewPort *WVP;
  52. long Text(),Wait();
  53.  
  54. void Move(),ReplyMsg(),Delay(),CloseLibrary(),CloseWindow(),CloseScreen();
  55. void ColorWindow(),SetAPen(),WritePixel(),scanmenu(),newscreen(),SetRGB4();
  56. void Draw(),RectFill(),SetMenuStrip(),ClearMenuStrip(),OnMenu(),OffMenu();
  57. void ShutDown(),ScreenToFront(),SavePic(),PutBoolGadget(),PutGadget();
  58. void newmenu();
  59. ULONG class;
  60. USHORT code;
  61. short AddGadget(),GetRGB4();
  62. short tmpcol,mennum,itmnum,subnum;
  63. long WriteILBMFile();
  64. void about(),RefreshGadgets();
  65. void runfractal(),run1fractal();
  66. void getfractal(),get1fractal();
  67. void switchrun(),switchfrac();
  68.  
  69. /* functions in file formulas2.c */
  70. void stratt();
  71.  
  72. void toggletitle(),ShowTitle();
  73. double sqrt(),atan(),log(),atof(),exp(),sin(),cos(),fabs();
  74.  
  75. struct RastPort *rport;
  76.  
  77.  
  78. main()
  79. {
  80.  
  81. IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",0L);
  82. if(IntuitionBase==NULL){printf("Error opening intuition!\n");ShutDown();};
  83.  
  84. GfxBase=(struct GfxBase *)OpenLibrary("graphics.library",0L);
  85. if(GfxBase==NULL){printf("Error opening graphics!\n");ShutDown();};
  86.  
  87. scr=openscreen(width,height,5,0);
  88. if(scr==NULL){printf("Error opening screen!\n");ShutDown();};
  89.  
  90. wdw=openwindow(scr,0,0,scr->Width,scr->Height,
  91.        (ULONG)(ACTIVATE|SMART_REFRESH|NOCAREREFRESH|BACKDROP|BORDERLESS),
  92.        (USHORT)MENUPICK);
  93. if(wdw==NULL){printf("Error opening window!\n");ShutDown();};
  94.  
  95. WVP=(struct ViewPort *)ViewPortAddress(wdw);
  96. SetRGB4(WVP,0L,0L,0L,0L);
  97. SetRGB4(WVP,1L,15L,15L,15L);
  98.  
  99. menptr=(men+0);
  100.  
  101. do
  102. {
  103. SetMenuStrip(wdw,menptr);
  104. Wait(1L << wdw->UserPort->mp_SigBit);
  105. ClearMenuStrip(wdw);
  106.    while(imsg=(struct IntuiMessage *)GetMsg(wdw->UserPort))
  107.       {
  108.        class=imsg->Class;
  109.        code=imsg->Code;
  110.        ReplyMsg((struct Message *)imsg);
  111.        if(class==MENUPICK)
  112.           {
  113.            mennum=MENUNUM(code);itmnum=ITEMNUM(code);subnum=SUBNUM(code);
  114.            if(mennum==MENU0)
  115.               {
  116.                if(itmnum==ABOUT)about();
  117.                if(itmnum==TITLE)toggletitle();
  118.                if(itmnum==START)switchrun();
  119.                if(itmnum==COLOR)ColorWindow(scr);
  120.                if(itmnum==SAVE)SavePic();
  121.               };
  122.            if(mennum==MENU1)
  123.               {
  124.                if(itmnum==NEXT)newmenu();
  125.                if(itmnum!=NEXT)switchfrac();
  126.               };
  127.            if(mennum==MENU2)newscreen();
  128.            if(mennum==MENU3)surface=itmnum;
  129.           };
  130.      };
  131. }
  132. while((mennum!=MENU0)||(itmnum!=QUIT));
  133.  
  134. if(wdw)          CloseWindow(wdw);
  135. if(scr)          CloseScreen(scr);
  136. if(GfxBase)      CloseLibrary(GfxBase);
  137. if(IntuitionBase)CloseLibrary(IntuitionBase);
  138. }
  139.  
  140. void newscreen()
  141. {
  142. if(itmnum==LO)width=320;
  143. if(itmnum==HI)width=640;
  144. if(itmnum==NO)height=TV_SYSTEM;
  145. if(itmnum==LA)height=2*TV_SYSTEM;
  146. depth=5;viewmode=0;
  147. if(height>300)  viewmode |= LACE;
  148. if(width==640){ viewmode |= HIRES; depth=4; };
  149.  
  150. if(wdw)CloseWindow(wdw);
  151. if(scr)CloseScreen(scr);
  152. scr=NULL;wdw=NULL;
  153. scr=openscreen(width,height,depth,viewmode);
  154. if(scr!=NULL)
  155.   {
  156.    wdw=openwindow(scr,0,0,scr->Width,scr->Height,
  157.        (ULONG)(ACTIVATE|SMART_REFRESH|NOCAREREFRESH|BACKDROP|BORDERLESS),
  158.        (USHORT)MENUPICK);
  159.   };
  160. if((scr==NULL)||(wdw==NULL))
  161.   {
  162.    if(scr)CloseScreen(scr);
  163.    scr=NULL;wdw=NULL;
  164.    mit[7].Flags=CHECKED|CHECKIT|ITEMTEXT|HIGHBOX|ITEMENABLED;
  165.    mit[8].Flags=CHECKIT|ITEMTEXT|HIGHBOX|ITEMENABLED;
  166.    mit[9].Flags=CHECKED|CHECKIT|ITEMTEXT|HIGHBOX|ITEMENABLED;
  167.    mit[10].Flags=CHECKIT|ITEMTEXT|HIGHBOX|ITEMENABLED;
  168.    viewmode=0;width=320;height=TV_SYSTEM;depth=5;
  169.  
  170.    scr=openscreen(width,height,depth,viewmode);
  171.    if(scr==NULL){printf("Error opening screen!\n");ShutDown();};
  172.  
  173.    wdw=openwindow(scr,0,0,scr->Width,scr->Height,
  174.        (ULONG)(ACTIVATE|SMART_REFRESH|NOCAREREFRESH|BACKDROP|BORDERLESS),
  175.        (USHORT)MENUPICK);
  176.    if(wdw==NULL){printf("Error opening window!\n");ShutDown();};
  177.  
  178.   };
  179. WVP=(struct ViewPort *)ViewPortAddress(wdw);
  180. SetRGB4(WVP,0L,0L,0L,0L);
  181. SetRGB4(WVP,1L,15L,15L,15L);
  182. }
  183.  
  184. struct Window *openwindow(scr,left,top,width,height,flags,idcmp)
  185. struct Screen *scr;
  186. SHORT left,top,width,height;
  187. ULONG flags;
  188. USHORT idcmp;
  189. {
  190. struct NewWindow nwdw;
  191. nwdw.LeftEdge=left;
  192. nwdw.TopEdge=top;
  193. nwdw.Width=width;
  194. nwdw.Height=height;
  195. nwdw.DetailPen=0;
  196. nwdw.BlockPen=1;
  197. nwdw.Title=NULL;
  198. nwdw.Flags=flags;
  199. nwdw.IDCMPFlags=idcmp;
  200. nwdw.Type=CUSTOMSCREEN;
  201. nwdw.FirstGadget=NULL;
  202. nwdw.CheckMark=NULL;
  203. nwdw.Screen=scr;
  204. nwdw.BitMap=NULL;
  205. nwdw.MinWidth=0;
  206. nwdw.MaxWidth=0;
  207. nwdw.MinHeight=0;
  208. nwdw.MaxHeight=0;
  209. return(OpenWindow(&nwdw));
  210. }
  211.  
  212.  
  213. void toggletitle()
  214. {
  215. titelflag=1-titelflag;
  216. ShowTitle(scr,titelflag);
  217. }
  218.  
  219.  
  220.  
  221. void scanmenu()
  222. {
  223. while(imsg=(struct IntuiMessage *)GetMsg(wdw->UserPort))
  224.     {
  225.      class=imsg->Class;
  226.      code=imsg->Code;
  227.      ReplyMsg((struct Message *)imsg);
  228.      if(class==MENUPICK)
  229.         {
  230.          mennum=MENUNUM(code);itmnum=ITEMNUM(code);subnum=SUBNUM(code);
  231.          if(mennum==MENU0)
  232.              {
  233.               switch(itmnum)
  234.                  {
  235.                   case 0: {xc=xoffset=width;yc=yoffset=height;break;};
  236.                   case 1: {ClearMenuStrip(wdw);ColorWindow(scr);
  237.                            SetMenuStrip(wdw,(men+3));break;};
  238.                   case 2: {toggletitle();break;};
  239.                  };
  240.              };
  241.         };
  242.     };
  243. }
  244.  
  245.  
  246. void PutGadget(text,chrs,xpos,ypos,gadptr)
  247. UBYTE *text;
  248. short chrs,xpos,ypos;
  249. struct Gadget *gadptr;
  250. {
  251. Move(rport,(long)xpos,(long)ypos);
  252. ypos+=5;
  253. Text(rport,text,(long)chrs);
  254. RectFill(rport,(long)(xpos-1),(long)(ypos-1),
  255.          (long)(xpos+(*gadptr).Width-9),(long)(ypos+(*gadptr).Height-1));
  256. (*gadptr).LeftEdge=xpos;
  257. (*gadptr).TopEdge=ypos;
  258. AddGadget(gwdw,gadptr,0L);
  259. }
  260.  
  261. void PutBoolGadget(xpos,ypos,gadptr)
  262. short xpos,ypos;
  263. struct Gadget *gadptr;
  264. {
  265. RectFill(rport,(long)(xpos),(long)(ypos),
  266.          (long)(xpos+(*gadptr).Width),(long)(ypos+(*gadptr).Height));
  267. (*gadptr).LeftEdge=xpos;
  268. (*gadptr).TopEdge=ypos;
  269. AddGadget(gwdw,gadptr,0L);
  270. RefreshGadgets(gadptr,gwdw,NULL);
  271. }
  272.  
  273. struct Screen *openscreen(width,height,depth,viewmodes)
  274. short width,height,depth;
  275. unsigned short viewmodes;
  276. {
  277. struct NewScreen nscr;
  278. nscr.LeftEdge=0;
  279. nscr.TopEdge=0;
  280. nscr.Width=width;
  281. nscr.Height=height;
  282. nscr.Depth=depth;
  283. nscr.DetailPen=0;
  284. nscr.BlockPen=1;
  285. nscr.ViewModes=viewmodes;
  286. nscr.Type=CUSTOMSCREEN;
  287. nscr.Font=NULL;
  288. nscr.DefaultTitle=(UBYTE *)SCREENTITLE;
  289. nscr.Gadgets=NULL;
  290. nscr.CustomBitMap=NULL;
  291. return(OpenScreen(&nscr));
  292. }
  293.  
  294. void about()
  295. {
  296. gwdw=openwindow(scr,50,15,200,170,(ULONG)ACTIVATE,(USHORT)GADGETUP,NULL);
  297. rport=gwdw->RPort;
  298. SetAPen(rport,1L);
  299. Move(rport,65L,10L);Text(rport,"FRACTALS",8L);
  300. Move(rport,10L,30L);Text(rport,"By Ronnie Johansson",19L);
  301. Move(rport,10L,40L);Text(rport,"student of Mathematics",22L);
  302. Move(rport,10L,50L);Text(rport,"University of Linkoping",23L);
  303. Move(rport,10L,70L);Text(rport,"If you want to contact",22L);
  304. Move(rport,10L,80L);Text(rport,"me, my address is :",19L);
  305. Move(rport,10L,90L);Text(rport,"Hasselkulleg. 70",16L);
  306. Move(rport,10L,100L);Text(rport,"461 62 TROLLHATTAN",18L);
  307. Move(rport,10L,110L);Text(rport,"            SWEDEN",18L);
  308.  
  309. PutBoolGadget(110,130,(gadb+0));
  310.  
  311. Wait(1L << gwdw->UserPort->mp_SigBit);
  312. while(imsg=(struct IntuiMessage *)GetMsg(gwdw->UserPort))
  313.       ReplyMsg((struct Message *)imsg);
  314. CloseWindow(gwdw);
  315. }
  316.  
  317.  
  318. void SavePic()
  319. {
  320. long success;
  321. char saveflag;
  322. saveflag=0;
  323. gwdw=openwindow(scr,50,50,150,100,(ULONG)ACTIVATE,
  324.                 (USHORT)(GADGETUP),NULL);
  325. rport=gwdw->RPort;
  326. SetAPen(rport,1L);
  327. Move(rport,10L,10L);Text(rport,"SAVE - Fractal",14L);
  328. PutGadget("Name",4,10,30,(gad+15));
  329.  
  330. PutBoolGadget(10,70,(gadb+1));
  331. PutBoolGadget(90,70,(gadb+2));
  332.  
  333. Wait(1L << gwdw->UserPort->mp_SigBit);
  334. while(imsg=(struct IntuiMessage *)GetMsg(gwdw->UserPort))
  335.    {
  336.       if((((struct Gadget *)(imsg->IAddress))->GadgetID)==2)saveflag=1;
  337.       ReplyMsg((struct Message *)imsg);
  338.    };
  339. CloseWindow(gwdw);
  340. if(saveflag==1)
  341.   {
  342.    ShowTitle(scr,titelflag=0L);
  343.    success=WriteILBMFile(namebuf,scr);
  344.    ShowTitle(scr,titelflag=1L);
  345.  
  346.    /* Print result window */
  347.    gwdw=openwindow(scr,50,50,150,100,(ULONG)ACTIVATE,
  348.                 (USHORT)(GADGETUP),NULL);
  349.    rport=gwdw->RPort;
  350.    SetAPen(rport,1L);
  351.    Move(rport,10L,10L);
  352.    if(success==WSAVE)
  353.         { Text(rport,"Picture saved.",14L);    };
  354.    if(success==NOSAVE)
  355.         { Text(rport,"Error :",7L);            Move(rport,10L,20L);
  356.           Text(rport,"Saving file.",12L); Move(rport,10L,30L);
  357.           Text(rport,"File removed...",15L);   };
  358.    if(success==NOOPEN)
  359.         { Text(rport,"Error :",7L);            Move(rport,10L,20L);
  360.           Text(rport,"Opening file.",13L);     Move(rport,10L,30L);
  361.           Text(rport,"File not saved.",15L);   };
  362.    PutBoolGadget(90,70,(gadb+0));
  363.    ScreenToFront(scr);
  364.    Wait(1L << gwdw->UserPort->mp_SigBit);
  365.    while(imsg=(struct IntuiMessage *)GetMsg(gwdw->UserPort))
  366.           ReplyMsg((struct Message *)imsg);
  367.    CloseWindow(gwdw);
  368.   };
  369. }
  370.  
  371. void ShutDown()
  372. {
  373. if(wdw)          CloseWindow(wdw);
  374. if(scr)          CloseScreen(scr);
  375. if(GfxBase)      CloseLibrary(GfxBase);
  376. if(IntuitionBase)CloseLibrary(IntuitionBase);
  377. exit(10);
  378. }
  379.  
  380.  
  381. void newmenu()
  382. {
  383. switch(fracmenu)
  384.   {
  385.    case 0: { menptr=(men+5);
  386.              break; };
  387.    case 1: { menptr=(men+0);
  388.              break; };
  389.   };
  390.  
  391. fracmenu++;
  392. if(fracmenu>1)fracmenu=0;
  393. }
  394.  
  395.  
  396. void switchrun()
  397. {
  398. /* All algorithms can not use the standard plotting routines
  399.    ,therefore we use switch to call appropriate function.
  400. */
  401. switch(fracmenu)
  402.   {
  403.    case 0: { runfractal();break; };
  404.    case 1: { run1fractal();break; };
  405.   };
  406. }
  407.  
  408.  
  409. void switchfrac()
  410. {
  411. /* All frac menues have their own getfrac menu
  412. */
  413. switch(fracmenu)
  414.   {
  415.    case 0: { getfractal();break; };
  416.    case 1: { get1fractal();break; };
  417.   };
  418. }
  419.  
  420.  
  421.  
  422.  
  423.  
  424.