home *** CD-ROM | disk | FTP | other *** search
/ Rat's Nest 1 / ratsnest1.iso / prgmming / c / julia2.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-19  |  4.3 KB  |  130 lines

  1. Path: unixg.ubc.ca!news.mic.ucla.edu!library.ucla.edu!europa.eng.gtefsd.com!paladin.american.edu!auvm!C53000.PETROBRAS.ANRJ.BR!BJ06
  2.  
  3. Comments: Gated by NETNEWS@AUVM.AMERICAN.EDU
  4.  
  5. Newsgroups: bit.listserv.frac-l
  6.  
  7. Return-Path: <@AUVM.AMERICAN.EDU,@VTBIT.CC.VT.EDU:FRAC-L@GITVM1.BITNET>
  8.  
  9. X-Envelope-to: FRAC-L@GITVM1.BITNET
  10.  
  11. X-VMS-To: @FRACTAL
  12.  
  13. References: ANSP network   HEPnet SPAN Bitnet Internet gateway
  14.  
  15. Message-ID: <D540EE19E0001851@fpsp.fapesp.br>
  16.  
  17. Date: Fri, 7 Jan 1994 11:02:00 BDB
  18.  
  19. Sender: "\"FRACTAL\" discussion list" <FRAC-L@GITVM1.BITNET>
  20.  
  21. Comments: @FPSP.FAPESP.BR - @FPSP.HEPNET - @BRFAPESP.BITNET - .BR gateway
  22.  
  23. From: BJ06@C53000.PETROBRAS.ANRJ.BR
  24.  
  25. Subject: JULIA2.CPP (C++ 3.1 source code)
  26.  
  27. Lines: 113
  28.  
  29.  
  30.  
  31. ---Program JULIA2.CPP---Begin---CUT HERE-----------------------------
  32.  
  33. //+-----------------------------------------------------------------+
  34.  
  35. //+ Program JULIA2.CPP                                              +
  36.  
  37. //+ OBS: Needs SVGA256 package (SVGA256.H & SVGA256.BGI) and        +
  38.  
  39. //       1024 x 768 points, 256 colours screen.                     +
  40.  
  41. //+ By F.A.A. Barbuto, January 1994.                                +
  42.  
  43. //+ Usage:                                                          +
  44.  
  45. //+      JULIA2 <pmin> <qmin> <xmin> <xmax> <ymin> <ymax> <maxiter> +
  46.  
  47. //+ Example:                                                        +
  48.  
  49. //       JULIA2 -0.74356 0.11135 -2.0 2.0 -2.0 2.0 256              +
  50.  
  51. //+-----------------------------------------------------------------+
  52.  
  53.  
  54.  
  55. #include <stdio.h>
  56.  
  57. #include <conio.h>
  58.  
  59. #include <graphics.h>
  60.  
  61. #include <math.h>
  62.  
  63. #include <stdlib.h>
  64.  
  65. #include "Svga256.h"
  66.  
  67. //void far initgraph(int far *,int far *,char far *);
  68.  
  69.  
  70.  
  71. int huge DetectVGA256()
  72.  
  73. {
  74.  
  75.   int Vid=4;
  76.  
  77.   return Vid;
  78.  
  79. }
  80.  
  81.  
  82.  
  83. void main(int argc, char *argv[])
  84.  
  85. {
  86.  
  87.       double xmin, xmax, ymin, ymax, fact=1.0;
  88.  
  89.       double ypy, x, y, x0, y0, xp, yp, const_scr=1.0;
  90.  
  91.       double deltax, deltay, p, q, ya, xkp1, ykp1, r;
  92.  
  93.       register int npix=1024, npiy=768, kcolor;
  94.  
  95.       register int k, np, nq, npy, ipen;
  96.  
  97.       char *endptr;
  98.  
  99.       int graphdriver=DETECT;
  100.  
  101.       int graphmode;
  102.  
  103.  
  104.  
  105.       p = strtod(argv[1],&endptr);
  106.  
  107.       q = strtod(argv[2],&endptr);
  108.  
  109.       xmin = strtod(argv[3],&endptr);
  110.  
  111.       xmax = strtod(argv[4],&endptr);
  112.  
  113.       ymin = strtod(argv[5],&endptr);
  114.  
  115.       ymax = strtod(argv[6],&endptr);
  116.  
  117.       kcolor = atoi(argv[7]);
  118.  
  119.       if(kcolor == 0) kcolor = 256;
  120.  
  121.  
  122.  
  123.       installuserdriver("Svga256",DetectVGA256);
  124.  
  125.       initgraph(&graphdriver, &graphmode, "c:\\borlandc\\bgi");
  126.  
  127.       if(fact>=1.0 || fact <=0.0)
  128.  
  129.         fact = 1.0;
  130.  
  131.       else {
  132.  
  133.         npix = (int)(npix*fact);
  134.  
  135.         npiy = (int)(npiy*fact);
  136.  
  137.       }
  138.  
  139.       ypy = (double)npiy - 0.5;
  140.  
  141.       deltax = (xmax-xmin)/(npix-1);
  142.  
  143.       deltay = (ymax-ymin)/(npiy-1);
  144.  
  145.  
  146.  
  147.       cleardevice();
  148.  
  149.       for (np=0; np<=npix-1; np++) {
  150.  
  151.         x0 = xmin + (double)np*deltax;
  152.  
  153.         for (nq=0; nq<=npiy-1; nq++) {
  154.  
  155.         y0 = ymin + (double)nq*deltay;
  156.  
  157.         x = x0;
  158.  
  159.         y = y0;
  160.  
  161.         k  = 0;
  162.  
  163.  
  164.  
  165. //     Real part of Z = XKP1 ; Imaginary part of Z = YKP1
  166.  
  167. //     Parte real: XKP1 ; Imaginaria: YKP1
  168.  
  169.  
  170.  
  171.          do {
  172.  
  173.            xkp1 = (x+y)*(x-y) + p;
  174.  
  175.            ya   = x*y;
  176.  
  177.            ykp1 = ya + ya + q;
  178.  
  179.            r    = xkp1*xkp1 + ykp1*ykp1;
  180.  
  181.            k++;
  182.  
  183.  
  184.  
  185. //     If R > M  the point escape towards infinity.
  186.  
  187. //     Se R > M, o ponto escapa para o infinito.
  188.  
  189.  
  190.  
  191.            if (r >= kcolor) {
  192.  
  193.              ipen = k;
  194.  
  195.              xp = const_scr*(double)np;
  196.  
  197.              yp = (double)nq;
  198.  
  199.              putpixel(xp,yp,ipen);
  200.  
  201.            }
  202.  
  203.  
  204.  
  205. //      Converging points is blue colour.
  206.  
  207. //      Pontos que convergem para o atrator; coloracao azul.
  208.  
  209.  
  210.  
  211.            if (k == kcolor) {
  212.  
  213.              ipen = 1;
  214.  
  215.              xp = const_scr*(double)np;
  216.  
  217.              yp = (double)nq;
  218.  
  219.              putpixel(xp,yp,ipen);
  220.  
  221.            }
  222.  
  223.  
  224.  
  225. //      Returns if no convergence is achieved on either escape or atraction.
  226.  
  227. //      Retorna se nao houver convergencia na fuga ou atracao.
  228.  
  229.  
  230.  
  231.            x = xkp1;
  232.  
  233.            y = ykp1;
  234.  
  235.          } while (r <= kcolor && k<=kcolor);
  236.  
  237.        }
  238.  
  239.        if(kbhit()) break;
  240.  
  241.      }
  242.  
  243.  
  244.  
  245. //   Clean-up.
  246.  
  247. //   Fechamento.
  248.  
  249.  
  250.  
  251.      getch();
  252.  
  253.      closegraph();
  254.  
  255. }
  256.  
  257. ---Program JULIA2.CPP---End---CUT HERE--------------------------
  258.  
  259.