|
25 Years of Programming
An open source source for C, C++, OWL, BASIC, MDB, XLS, DOT, and more... |
Home Projects Up Sitemap Search Blog Forum+Chat About Us Privacy Terms of Use Feedback FAQ Images Services Ads Donate Humor |
|
|
Logistic map bifurcation diagram,
|
|
/* bif.c 4-23-93 4-29-93
Copyright (C)1993 Steven Whitney. Published under the
GNU GPL (General Public License) Version 2, with ABSOLUTELY NO WARRANTY.
SHOWS ROBERT MAY'S BIFURCATION DIAGRAM, AS DESCRIBED IN
CHAOS: MAKING A NEW SCIENCE, BY JAMES GLEICK.
4-29-93 zedsave() is now a library function
*/
#include "stdio.h"
main(argc,argv)
int argc;
char **argv;
{
char ch; /* user input */
int i; /* loop counter */
int dupcount; /* how many pixels are already set */
int maxdups = 100; /* most duplicate points allowed */
int screenx, screeny; /* screen coordinates */
int color; /* color to use */
double hibound, lobound, step;
double x;
double r;
double xfactor;
FILE *outfile; /* .ZED graphics output file */
if(argc > 1)
if((maxdups = atoi(argv[1])) == 0)
abort("Command line error.");
puts("The interesting things happen from about 3.2 to 4.0\n\n");
puts("--> Press 'S' at any time to save...");
puts(" anything else to quit.\n\n");
puts("Enter lower bound (0 to < 4): ");
scanf("%lf",&lobound);
puts("Enter upper bound (= or < 4): ");
scanf("%lf",&hibound);
step = (hibound - lobound) / 639.;
xfactor = 639. / (hibound - lobound);
puts("\033z");
cls();
puts("\033x1"); /* enable 25th line */
puts("\033x5"); /* turn cursor off */
puts("\033x<\033y@"); /* disable auto-repeat & event mode */
for(r = lobound ; r <= hibound ; r += step)
{
x = .5;
locate(1,1);
printf("r=%f of %f to %f",r,lobound,hibound);
for(i = 0 ; i < 100 ; i++) /* allow equation to settle down */
x = (r * x) - (r * x * x);
dupcount = 0;
for(i = 0 ; i < 1000 ; i++) /* calc 1000 points to plot */
{
if(ch = csts())
{
if(tolower(ch) == 's')
zedsave();
else
exit(0);
}
x = (r * x) - (r * x * x);
screenx = (int)((r-lobound)*xfactor);
screeny = (int)(224. - (x * 224.));
color = point(screenx,screeny);
/* if 100 points are dups, move on to next interval */
if(color)
if(++dupcount == maxdups)
break;
/* the more times a point gets hit, the brighter the color */
pset(screenx,screeny,MIN(color+1,7));
}
}
zedsave();
getchar();
puts("\033z"); /* reset terminal */
puts("Remember to rename SCREEN.ZED before creating another one.\n");
exit(0);
}
|
|
|
|
|
|