home *** CD-ROM | disk | FTP | other *** search
/ Rat's Nest 1 / ratsnest1.iso / prgmming / c / julia.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-19  |  4.3 KB  |  129 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: <D4F0D9EB00001739@fpsp.fapesp.br>
  16.  
  17. Date: Fri, 7 Jan 1994 11:00: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: JULIA.CPP (C++ 3.1 source code)
  26.  
  27. Lines: 112
  28.  
  29.  
  30.  
  31. ---Program JULIA.CPP---Begin---CUT HERE-----------------------------
  32.  
  33. //+----------------------------------------------------------------+
  34.  
  35. //+ Program JULIA.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. //+      JULIA <pmin> <qmin> <xmin> <xmax> <ymin> <ymax> <maxiter> +
  46.  
  47. //+ Example:                                                       +
  48.  
  49. //       JULIA -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.       register double xmin, xmax, ymin, ymax, fact=1.0;
  88.  
  89.       register double ypy, x, y, x0, y0, xp, yp, const_scr=1.0;
  90.  
  91.       register double deltax, deltay, p, q, ya, r, xkp1, ykp1;
  92.  
  93.       register int npix=1024, npiy=768, kcolor;
  94.  
  95.       register int k, np, nq, 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.       deltax = (xmax-xmin)/(double)(npix-1);
  140.  
  141.       deltay = (ymax-ymin)/(double)(npiy-1);
  142.  
  143.  
  144.  
  145.       cleardevice();
  146.  
  147.       for (np=0; np<=npix-1; np++) {
  148.  
  149.         x0 = xmin + (double)np*deltax;
  150.  
  151.         for (nq=0; nq<=npiy-1; nq++) {
  152.  
  153.           y0 = ymin + (double)nq*deltay;
  154.  
  155.           x = x0;
  156.  
  157.           y = y0;
  158.  
  159.           k  = 0;
  160.  
  161.  
  162.  
  163. //  Real part: XKP1 ; Imaginary: YKP1
  164.  
  165. //  Parte real: XKP1 ; Imaginaria: YKP1
  166.  
  167.  
  168.  
  169.           do {
  170.  
  171.             xkp1 = (x+y)*(x-y) + p;
  172.  
  173.             ya   = x*y;
  174.  
  175.             ykp1 = ya + ya + q;
  176.  
  177.             r    = xkp1*xkp1 + ykp1*ykp1;
  178.  
  179.             k++;
  180.  
  181.  
  182.  
  183. // If R > M the point escapes towards infinity.
  184.  
  185. // Se R > M, o ponto escapa para o infinito.
  186.  
  187.  
  188.  
  189.             if (r >= kcolor) {
  190.  
  191.               ipen = 30 + k;
  192.  
  193.               xp = const_scr*(double)np;
  194.  
  195.               yp = (double)nq;
  196.  
  197.               putpixel(xp,yp,ipen);
  198.  
  199.             }
  200.  
  201.  
  202.  
  203. // Converging points in blue colour.
  204.  
  205. // Pontos que convergem para o atrator; coloracao azul.
  206.  
  207.  
  208.  
  209.             if (k == kcolor) {
  210.  
  211.               ipen = 1;
  212.  
  213.               xp = const_scr*(double)np;
  214.  
  215.               yp = (double)nq;
  216.  
  217.               putpixel(xp,yp,ipen);
  218.  
  219.             }
  220.  
  221.  
  222.  
  223. // Returns if no convergence is achieved on either escape or atraction.
  224.  
  225. // Retorna se nao houver convergencia na fuga ou atracao.
  226.  
  227.  
  228.  
  229.             x = xkp1;
  230.  
  231.             y = ykp1;
  232.  
  233.           } while (r <= kcolor && k<=kcolor);
  234.  
  235.         }
  236.  
  237.           if(kbhit()) break;
  238.  
  239.       }
  240.  
  241.  
  242.  
  243. // Clean-up.
  244.  
  245. // Fecha a parte grafica.
  246.  
  247.  
  248.  
  249.       getch();
  250.  
  251.       closegraph();
  252.  
  253. }
  254.  
  255. ---Program JULIA.CPP---End---CUT HERE--------------------------------
  256.  
  257.