home *** CD-ROM | disk | FTP | other *** search
/ Rat's Nest 1 / ratsnest1.iso / prgmming / c / duff.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-19  |  3.0 KB  |  91 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. X-Envelope-to: FRAC-L@GITVM1.BITNET
  8.  
  9. X-VMS-To: @FRACTAL
  10.  
  11. References: ANSP network   HEPnet SPAN Bitnet Internet gateway
  12.  
  13. Message-ID: <EECB3E0D80010C24@fpsp.fapesp.br>
  14.  
  15. Date: Tue, 19 Apr 1994 09:27:00 BSC
  16.  
  17. Sender: "\"FRACTAL\" discussion list" <FRAC-L@GITVM1.BITNET>
  18.  
  19. Comments: @FPSP.FAPESP.BR - @FPSP.HEPNET - @BRFAPESP.BITNET - .BR gateway
  20.  
  21. From: BJ06@C53000.PETROBRAS.ANRJ.BR
  22.  
  23. Subject: DUFFING.CPP (C++ 3.1 source code)
  24.  
  25. Lines: 75
  26.  
  27.  
  28.  
  29. ---Program DUFFING.CPP---Begin---CUT HERE--------------------------------
  30.  
  31. //
  32.  
  33. //+---------------------------------------------------------------------+
  34.  
  35. //+ Program DUFFING.CPP                                                 +
  36.  
  37. //+ By Ramiro Perez {RPEREZ@UTPVM1.BITNET}, (Panama)                    +
  38.  
  39. //+ and Fausto A. A. Barbuto {BJ06@C53000.PETROBRAS.ANRJ.BR}, (Brazil). +
  40.  
  41. //+ C++ 3.1 programme's creator: Fausto A. A. Barbuto, April 18, 1994.  +
  42.  
  43. //+ After a TURBO BASIC program by Ramiro Perez.                        +
  44.  
  45. //+                                                                     +
  46.  
  47. //+ Plots Duffing's oscillator with shaded, colourful spheres.          +
  48.  
  49. //+                                                                     +
  50.  
  51. //+ VGA 16 colours version.                                             +
  52.  
  53. //+ Press any key to stop and PAUSE to freeze the execution.            +
  54.  
  55. //+---------------------------------------------------------------------+
  56.  
  57. //
  58.  
  59. #include <graphics.h>
  60.  
  61. #include <conio.h>
  62.  
  63. #include <stdio.h>
  64.  
  65. #include <dos.h>
  66.  
  67. #include <math.h>
  68.  
  69.  
  70.  
  71. void Draw (double, double, int);
  72.  
  73.  
  74.  
  75. void main()
  76.  
  77. {
  78.  
  79.     int k, k1;
  80.  
  81.     int ipal[14] = {8,1,9,25,11,43,31,32,4,52,36,38,54,62};
  82.  
  83.     double a, cl, t, x, y, x1, y1, pi=3.141592653589793, twopi;
  84.  
  85.     int graphdriver=DETECT, graphmode;
  86.  
  87.  
  88.  
  89.     initgraph(&graphdriver,&graphmode,"C:\\BORLANDC\\BGI");
  90.  
  91.     cleardevice();
  92.  
  93.  
  94.  
  95.     x = 1.0;
  96.  
  97.     y = 0.0;
  98.  
  99.     t = 0.0;
  100.  
  101.     a = 0.3;
  102.  
  103.     twopi = 2.0*pi;
  104.  
  105.     for (k=0;k<=13;k++) setpalette(k,ipal[k]);
  106.  
  107.  
  108.  
  109.     do {
  110.  
  111.       k1++;
  112.  
  113.       x1 = x + y/twopi;
  114.  
  115.       y1 = y + (-(x*x*x) + x -0.25*y + a*cos(t))/twopi;
  116.  
  117.       t  = 0.01*(k1 % 628);
  118.  
  119.       x = x1;
  120.  
  121.       y = y1;
  122.  
  123.       if (t > pi) cl = 0;
  124.  
  125.       else cl = 7;
  126.  
  127.       Draw(x,y,cl);
  128.  
  129.       delay(9); // Change the time delay to see the plot slower/faster
  130.  
  131.     } while (!kbhit());
  132.  
  133.     getch();
  134.  
  135.     closegraph();
  136.  
  137. }
  138.  
  139.  
  140.  
  141. void Draw (double x, double y, int cl)
  142.  
  143. {
  144.  
  145.     double i1, j1, c;
  146.  
  147.     int i, k, colour;
  148.  
  149.  
  150.  
  151.     i1 = 150.0*x + 320.0;
  152.  
  153.     j1 = -88.0*y + 240.0;
  154.  
  155.     k = 7;
  156.  
  157.  
  158.  
  159.     for (i=1;i<=7;i++) {
  160.  
  161.       c = 0.09*i;
  162.  
  163.       colour = (i + cl);
  164.  
  165.       setcolor(colour);
  166.  
  167.       setfillstyle(SOLID_FILL,k);
  168.  
  169.       circle ((int)(i1+c),(int)(j1+c),k);
  170.  
  171.       k--;
  172.  
  173.     }
  174.  
  175.     return;
  176.  
  177. }
  178.  
  179. ---Program DUFFING.CPP---End---CUT HERE---------------------------------
  180.  
  181.