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

  1. From:    MX%"BJ06@C53000.PETROBRAS.ANRJ.BR" 10-NOV-1994 13:59:13.00
  2.  
  3. To:    MX%"noel@erich.triumf.ca"
  4.  
  5. CC:    
  6.  
  7. Subj:    CLOUDS.CPP for spanky... THANKS!!!!!
  8.  
  9.  
  10.  
  11. Return-Path: <BJ06@C53000.PETROBRAS.ANRJ.BR>
  12.  
  13. Received: from fpsp.fapesp.br by Erich.Triumf.CA (MX V4.0-1 VAX) with SMTP;
  14.  
  15.           Thu, 10 Nov 1994 13:59:03 PST
  16.  
  17. Received: from DECNET-MAIL by fpsp.fapesp.br with PMDF#10108; Thu, 10 Nov 1994
  18.  
  19.           19:57 BDB (-0200 C)
  20.  
  21. Date: Thu, 10 Nov 1994 19:57 BDB (-0200 C)
  22.  
  23. From: "FAUSTO Arinos de Almeida Barbuto (Totxo)"
  24.  
  25.       <BJ06@C53000.PETROBRAS.ANRJ.BR>
  26.  
  27. Subject: CLOUDS.CPP for spanky... THANKS!!!!!
  28.  
  29. To: noel@erich.triumf.ca
  30.  
  31. Message-ID: <5DC38B8160001186@fpsp.fapesp.br>
  32.  
  33. X-Envelope-to: noel@erich.triumf.ca
  34.  
  35. X-VMS-To: @NOEL
  36.  
  37. References: ANSP network   HEPnet SPAN Bitnet Internet gateway
  38.  
  39. Comments: @FPSP.FAPESP.BR - @FPSP.HEPNET - @BRFAPESP.BITNET - .BR gateway
  40.  
  41.  
  42.  
  43. //+-------------------------------------------------------------------------+
  44.  
  45. //+ Program CLOUDS.CPP - November 10, 1994                                  +
  46.  
  47. //+                                                                         +
  48.  
  49. //+ By Fausto Arinos de Almeida Barbuto, Rio de Janeiro, RJ, BRAZIL         +
  50.  
  51. //+ E-mails: BJ06@C53000.PETROBRAS.ANRJ.BR  and  barbuto@ax.ibase.org.br    +
  52.  
  53. //+                                                                         +
  54.  
  55. //+ Plots clouds-like fractals (or burnt paper if you plot it with iopt=1)  +
  56.  
  57. //+ The plots are sequential with a delimiting delay of 1.5 seconds.        +
  58.  
  59. //+ Press ESC at any time to fade the screen out and quit.                  +
  60.  
  61. //+                                                                         +
  62.  
  63. //+ This program is no more than a PROTOTYPE; please improve it at your own +
  64.  
  65. //+ taste. ;-)                                                              +
  66.  
  67. //+ REFERENCE: Pickover, Clifford A. "Computers, Pattern, Chaos and Beauty" +
  68.  
  69. //+            1990, St.-Martin's Press, pg. 328                            +
  70.  
  71. //+                                                                         +
  72.  
  73. //+ This program is dedicated to Dr. Martin Erdelen and his continuous an-  +
  74.  
  75. //+ xiety in relation to the cummulus-nimbus and stratus-cirrus (?!) :-)    +
  76.  
  77. //+                                                                         +
  78.  
  79. //+ Uses SVGA256.BGI by Jordan Powell Hargrave plus Random Number Generator +
  80.  
  81. //+ and fade-out routine by Michael E. Sargent and Quintessential Sophistry.+
  82.  
  83. //+                                                                         +
  84.  
  85. //+ Version for spanky.triumf.ca (142.90.112.1), Vancouver, B.C. Canada.    +
  86.  
  87. //+*************************************************************************+
  88.  
  89. //+ Some interesting start-up combinations of random cycles (Cmax), radius  +
  90.  
  91. //+ (Rmax) and colouring scheme (iopt):                                     +
  92.  
  93. //+                                                                         +
  94.  
  95. //+ Cmax =  500 Rmax = 30  iopt = 2 ###  Cmax = 1000 Rmax = 5   iopt = 1    +
  96.  
  97. //+ Cmax =  200 Rmax =  3  iopt = 1 ###  Cmax =  250 Rmax = 3   iopt = 2    +
  98.  
  99. //+ Cmax = 2000 Rmax =  1  iopt = 2 ###  Cmax =   50 Rmax = 2   iopt = 2    +
  100.  
  101. //+ (The last example seems more to be a crystal seen under polarized light)+
  102.  
  103. //+-------------------------------------------------------------------------+
  104.  
  105. #include <math.h>
  106.  
  107. #include <graphics.h>
  108.  
  109. #include <conio.h>
  110.  
  111. #include <stdio.h>
  112.  
  113. #include <stdlib.h>
  114.  
  115. #include <dos.h>
  116.  
  117. #include "svga256.h"
  118.  
  119.  
  120.  
  121. double qsrandom(void);
  122.  
  123. void fade(void);
  124.  
  125.  
  126.  
  127. int Video;
  128.  
  129.  
  130.  
  131. int huge DetectSVGA256()
  132.  
  133. {
  134.  
  135.   printf("\n Which video mode would you like to use? \n\n");
  136.  
  137.   printf(" 0 - 320x200x256\n");
  138.  
  139.   printf(" 1 - 640x400x256\n");
  140.  
  141.   printf(" 2 - 640x480x256 (Suggested)\n");
  142.  
  143.   printf(" 3 - 800x600x256\n");
  144.  
  145.   printf(" 4 - 1024x768x256\n\n> ");
  146.  
  147.   scanf("%d",&Video);
  148.  
  149.   if ((Video>4) || (Video<0)) Video = 2;
  150.  
  151.   return(Video);
  152.  
  153. }
  154.  
  155.  
  156.  
  157. void main(void)
  158.  
  159. {
  160.  
  161.     int Raio[5000], Cx[5000], Cy[5000], colour, npix, npiy, iopt;
  162.  
  163.     float Tcor, Cor[5000];
  164.  
  165.     int  GraphDriver=DETECT, GraphMode;
  166.  
  167.     int xpix, ypix, Cmax, ic, index, dx, dy, Rmax;
  168.  
  169.  
  170.  
  171.     clrscr();
  172.  
  173.     printf("\n Program CLOUDS.CPP, by Fausto A. A. Barbuto");
  174.  
  175.     printf("\n\n Enter the number of random cycles");
  176.  
  177.     printf("\n (Suggested: 500, 1000, 1500, 2000 [Maximum = 5000])");
  178.  
  179.     printf("\n > ");
  180.  
  181.     scanf("%d",&Cmax);
  182.  
  183.     if (Cmax > 5000) Cmax = 2500;
  184.  
  185.  
  186.  
  187.     printf("\n\n Enter maximum length of the radius for a random circle");
  188.  
  189.     printf("\n (Suggested: > 5)");
  190.  
  191.     printf("\n > ");
  192.  
  193.     scanf("%d",&Rmax);
  194.  
  195.     if (Rmax > 640) Rmax = 25;
  196.  
  197.     printf("\n\n Scheme for colours:");
  198.  
  199.     printf("\n     From Dark Black to White     ---> Enter 1");
  200.  
  201.     printf("\n     Covering all the 256 colours ---> Enter 2");
  202.  
  203.     printf("\n > ");
  204.  
  205.     scanf("%d",&iopt);
  206.  
  207.     clrscr();
  208.  
  209.  
  210.  
  211.     installuserdriver("Svga256",DetectSVGA256);
  212.  
  213.     initgraph(&GraphDriver,&GraphMode,"C:\\BORLANDC\\BGI");
  214.  
  215.  
  216.  
  217.     if (Video == 0) {npix = 320; npiy = 200;}
  218.  
  219.     if (Video == 1) {npix = 640; npiy = 400;}
  220.  
  221.     if (Video == 2) {npix = 640; npiy = 480;}
  222.  
  223.     if (Video == 3) {npix = 800; npiy = 600;}
  224.  
  225.     if (Video == 4) {npix =1024; npiy = 768;}
  226.  
  227.  
  228.  
  229.     do {
  230.  
  231.       cleardevice();
  232.  
  233. //
  234.  
  235. //--> Creating circles with random position, radius and inner colour.
  236.  
  237. //
  238.  
  239.       for (ic=1; ic<=Cmax; ic++) {
  240.  
  241.     Cx[ic]   = (int)(npix*qsrandom());
  242.  
  243.     Cy[ic]   = (int)(npiy*qsrandom());
  244.  
  245.     Raio[ic] = (int)(Rmax*qsrandom());
  246.  
  247.     if (iopt == 1) Cor[ic]  = 16.0*qsrandom() + 15.0;
  248.  
  249.     else Cor[ic] = 256.0*qsrandom();
  250.  
  251.       }
  252.  
  253. //
  254.  
  255. //--> Scanning all points on the screen.
  256.  
  257. //
  258.  
  259.       for (xpix=0; xpix<=(npix-1); xpix++) {
  260.  
  261.     for (ypix=0; ypix<=(npiy-1); ypix++) {
  262.  
  263.       index = 0;
  264.  
  265.       Tcor  = 0;
  266.  
  267. //
  268.  
  269. //------> Checking whether the point is inside a particular circle or not.
  270.  
  271. //
  272.  
  273.       for (ic=1; ic<=Cmax; ic++) {
  274.  
  275.         dx = xpix - Cx[ic];
  276.  
  277.         dy = ypix - Cy[ic];
  278.  
  279.         if ((int)(dx*dx + dy*dy) <= Raio[ic]*Raio[ic]) {
  280.  
  281.           index++;
  282.  
  283.           Tcor = Tcor + Cor[ic];
  284.  
  285.         }
  286.  
  287.       }
  288.  
  289. //
  290.  
  291. //------> Calculating the average intensity of the point.
  292.  
  293. //
  294.  
  295.       if (index > 0) colour = (int)(Tcor/index);
  296.  
  297.       else colour = 0;
  298.  
  299.       putpixel(xpix,ypix,colour);
  300.  
  301.     }
  302.  
  303.     if (kbhit()) break;
  304.  
  305.       }
  306.  
  307.       delay(1500);
  308.  
  309.     } while (!kbhit());
  310.  
  311.     fade();
  312.  
  313.     closegraph();
  314.  
  315. }
  316.  
  317.  
  318.  
  319. //+=================================================+//
  320.  
  321. //+ Random number generator by Michael E. Sargent.  +//
  322.  
  323. //+=================================================+//
  324.  
  325.  
  326.  
  327. double qsrandom(void)
  328.  
  329. {
  330.  
  331.    int random_integer, temp_integer;
  332.  
  333.    double random_double, temp_double;
  334.  
  335.  
  336.  
  337.    random_integer = random(RAND_MAX);
  338.  
  339.    random_double = (double)random_integer / RAND_MAX;
  340.  
  341.    temp_integer = random(30519);
  342.  
  343.    temp_double = (double)temp_integer / 1000000000L;
  344.  
  345.    random_double += temp_double;
  346.  
  347.    return(random_double);
  348.  
  349. }
  350.  
  351.  
  352.  
  353. //+======================================================================+
  354.  
  355. // Fade-out routine by Michael E. Sargent & The Quintessential Sophistry +
  356.  
  357. //=======================================================================+
  358.  
  359. #pragma warn -eff
  360.  
  361. void fade(void)
  362.  
  363. {
  364.  
  365.    int a, b, p1, p2, p3;
  366.  
  367.  
  368.  
  369.    for (a=0; a<64; a++)
  370.  
  371.    {
  372.  
  373.       for (b=0; b<256; b++)
  374.  
  375.       {
  376.  
  377.      outp(0x3C7, b);
  378.  
  379.      p1 = inp(0x3C9);
  380.  
  381.      p2 = inp(0x3C9);
  382.  
  383.      p3 = inp(0x3C9);
  384.  
  385.      outp (0x3C8, b);
  386.  
  387.      if (p1 > 0) outp(0x3C9, p1 - 1);
  388.  
  389.         else outp(0x3C9, 0);
  390.  
  391.      if (p2 > 0) outp(0x3C9, p2 - 1);
  392.  
  393.         else outp(0x3C9, 0);
  394.  
  395.      if (p3 > 0) outp(0x3C9, p3 - 1);
  396.  
  397.         else outp(0x3C9, 0);
  398.  
  399.       }
  400.  
  401.    delay(100);
  402.  
  403.    }
  404.  
  405. }
  406.  
  407. #pragma warn +eff
  408.  
  409.