home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Rat's Nest 1
/
ratsnest1.iso
/
prgmming
/
c
/
duff.cpp
< prev
next >
Wrap
Text File
|
1996-02-19
|
3KB
|
91 lines
Path: unixg.ubc.ca!news.mic.ucla.edu!library.ucla.edu!europa.eng.gtefsd.com!paladin.american.edu!auvm!C53000.PETROBRAS.ANRJ.BR!BJ06
Comments: Gated by NETNEWS@AUVM.AMERICAN.EDU
Newsgroups: bit.listserv.frac-l
X-Envelope-to: FRAC-L@GITVM1.BITNET
X-VMS-To: @FRACTAL
References: ANSP network HEPnet SPAN Bitnet Internet gateway
Message-ID: <EECB3E0D80010C24@fpsp.fapesp.br>
Date: Tue, 19 Apr 1994 09:27:00 BSC
Sender: "\"FRACTAL\" discussion list" <FRAC-L@GITVM1.BITNET>
Comments: @FPSP.FAPESP.BR - @FPSP.HEPNET - @BRFAPESP.BITNET - .BR gateway
From: BJ06@C53000.PETROBRAS.ANRJ.BR
Subject: DUFFING.CPP (C++ 3.1 source code)
Lines: 75
---Program DUFFING.CPP---Begin---CUT HERE--------------------------------
//
//+---------------------------------------------------------------------+
//+ Program DUFFING.CPP +
//+ By Ramiro Perez {RPEREZ@UTPVM1.BITNET}, (Panama) +
//+ and Fausto A. A. Barbuto {BJ06@C53000.PETROBRAS.ANRJ.BR}, (Brazil). +
//+ C++ 3.1 programme's creator: Fausto A. A. Barbuto, April 18, 1994. +
//+ After a TURBO BASIC program by Ramiro Perez. +
//+ +
//+ Plots Duffing's oscillator with shaded, colourful spheres. +
//+ +
//+ VGA 16 colours version. +
//+ Press any key to stop and PAUSE to freeze the execution. +
//+---------------------------------------------------------------------+
//
#include <graphics.h>
#include <conio.h>
#include <stdio.h>
#include <dos.h>
#include <math.h>
void Draw (double, double, int);
void main()
{
int k, k1;
int ipal[14] = {8,1,9,25,11,43,31,32,4,52,36,38,54,62};
double a, cl, t, x, y, x1, y1, pi=3.141592653589793, twopi;
int graphdriver=DETECT, graphmode;
initgraph(&graphdriver,&graphmode,"C:\\BORLANDC\\BGI");
cleardevice();
x = 1.0;
y = 0.0;
t = 0.0;
a = 0.3;
twopi = 2.0*pi;
for (k=0;k<=13;k++) setpalette(k,ipal[k]);
do {
k1++;
x1 = x + y/twopi;
y1 = y + (-(x*x*x) + x -0.25*y + a*cos(t))/twopi;
t = 0.01*(k1 % 628);
x = x1;
y = y1;
if (t > pi) cl = 0;
else cl = 7;
Draw(x,y,cl);
delay(9); // Change the time delay to see the plot slower/faster
} while (!kbhit());
getch();
closegraph();
}
void Draw (double x, double y, int cl)
{
double i1, j1, c;
int i, k, colour;
i1 = 150.0*x + 320.0;
j1 = -88.0*y + 240.0;
k = 7;
for (i=1;i<=7;i++) {
c = 0.09*i;
colour = (i + cl);
setcolor(colour);
setfillstyle(SOLID_FILL,k);
circle ((int)(i1+c),(int)(j1+c),k);
k--;
}
return;
}
---Program DUFFING.CPP---End---CUT HERE---------------------------------