|
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 Payments Humor Music |
Side view of a .PIC file Mandelbrot image, DeSmet C for the Heathkit H-100 computerThe 3D.C program was an attempt to view Mandelbrot Set images from the side. In my Mandelbrot Set display programs, the escape times are used as color indexes into a palette, so the colors are not merely colors, but represent elevations. When you view the image normally, you can't see the elevations because, in effect, you're looking straight down on the region from above. You see the different colors, but don't see the geographical relief. This program takes a graphic file saved in my .PIC format, translates the colors (the elevations) to Y-axis values, and displays the Mandelbrot (or any image) from the side. This example output (click for full size) shows that as you get closer to the Mandelbrot Set itself, the elevations increase extremely rapidly. The smoothe.c program was originally written to flatten these designs out so they didn't look so steep. This side view method from 3D.C was carried all the way to the Borland OWL Mandelbrot program where it's one of the display options for .BMP files even though the visual effect has never achieved a level that's likely to make anybody gasp in amazement. |
/* 3D.C 11/20/93 1/4/06
Copyright (C)1993, 2006 Steven Whitney.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
Version 3 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
TAKES DATA FROM MBROT .PIC FILE AND INSTEAD OF PLOTTING A COLOR
AGAINST X & Y, (WHICH ESSENTIALLY GIVES A 3D VIEW FROM THE TOP),
IT TRANSLATES THE COLOR CODES INTO Y AXIS VALUES, AND
PLOTS THEM AGAINST X, FOR A SIDE-VIEW OF THE COUTOURS.
You have to have a good imagination to see it.
THIS PROGRAM USES SOME OF THE FUNCTIONS FROM MY LIBRARIES.
for area-fill, allow skipping lines:
display every 1th, 5th, 9th, 15th, 25th, 45th line.
*/
#include "stdio.h"
/*--------------------------------------------------------------------------*/
int colors[255];
/* actual screen colors to be rotated */
int scrcolors[7] = {1,2,3,4,5,6,7}; /* 7,1,6,2,5,3,4 wasn't so good */
int sccount = 7; /* NUMBER OF ELEMENTS IN SCRCOLORS, */
/* TO ALLOW SCRCOLORS VARIABLE # ELEMENTS */
/*--------------------------------------------------------------------------*/
/* clears the entire screen, including line 25. */
void clrscr()
{
locate(25,1);
puts("\033E");
locate(1,1);
puts("\033E");
}
/*--------------------------------------------------------------------------*/
/* color map file structure: color<cr>color<cr>... */
/* # lines in file must be at least MAXITERATIONS */
/* *EACH* possible iteration count has an associated color */
/* colors[MAXITERATIONS-1] should be 0 (black) */
/* Each iteration value maps to a color. The file provided to this function */
/* should be a text file of 255 lines, with one number on each line. */
/* Each number is the number of the color to use when plotting the */
/* iteration count corresponding to that line number in the file. */
/* Remember that the H100 only has 8 colors available, numbered 0-7. */
/* EXAMPLE: */
/* 1 <-- ESCAPE TIME OF 0 MAPS TO COLOR 1 */
/* 4 <-- ESCAPE TIME OF 1 MAPS TO COLOR 4 */
/* 5 <-- ESCAPE TIME OF 2 MAPS TO COLOR 5 */
/* ETC. */
/* See the end of mbrot.c for an example colors file. */
void loadcolors()
{
int i;
char filename[80];
FILE *infile;
puts(".COL (color) file to load: ");
gets(filename);
if(!(infile = fopen(filename,"r")))
abort("Input file not found.");
for(i = 0 ; i < MAXITERATIONS ; i++)
if(fscanf(infile,"%d\n",&(colors[i])) != 1)
abort(".COL file corrupt. Repair and rerun.");
fclose(infile);
}
/*--------------------------------------------------------------------------*/
main(argc,argv)
int argc;
char **argv;
{
int i, j;
int x, y, lastx, lasty;
double lowy, highy; /* RANGE OF VALUES IN INPUT FILE */
double yfactor; /* FOR SCALING TO SCREEN DIMENSIONS */
int color;
int fline; /* (SCAN)LINE # (FROM FILE) BEING DISPLAYED */
int iniskip = 0; /* number of leading lines to skip over completely */
int skip = 0; /* number of lines to skip between displayed lines */
char choice; /* MENU CHOICE */
char filename[80];
char databuf[640]; /* ONE LINE OF DATA FROM FILE */
FILE *infile;
if(argc != 2)
abort("Usage: 3D filename (omit .PIC)\n");
sprintf(filename,"%s.pic",argv[1]);
if(!(infile = fopen(filename,"r")))
abort("Input file not found.");
do
{
puts("Options: \n\n");
puts("0 - Quit.\n");
puts("1 - Plot points, using 2 pages\n");
puts("2 - Overlay points, no erase, 1 page\n");
puts("3 - Connect points with lines, using 2 pages\n");
puts("4 - Draw lines, no erase, 1 page only\n");
puts("5 - Fill area below curves, 1 page, colors = height\n");
puts("6 - Fill area below curves, 1 page, colors = nearness\n");
puts("Choice: ");
choice = tolower((char)getchar());
}
while((choice < '0') || (choice > '6'));
if(choice == '0')
exit(0);
puts("\nEnter lowest Y value in file: ");
scanf("%lf",&lowy);
puts("Enter highest Y value in file: ");
scanf("%lf",&highy);
yfactor = 224./(highy - lowy);
puts("Number of lines to jump over before start of display, <CR> for 0: ");
scanf("%d",&iniskip);
puts("Number of lines to skip between displayed lines, <CR> for 0: ");
scanf("%d",&skip);
puts("\033z\033x1\033x5"); /* RESET, ENABLE 25TH, CURSOR OFF */
_outb(0x78,0xd8); /* ALL PLANES ON */
flipcpu(); /* ERASE PAGE 2 */
clrscr();
flipcpu();
clrscr(); /* ERASE PAGE 1, CURSOR IS LEFT AT (1,1) */
for(j = 0 ; j < iniskip ; j++) /* skip over initial lines */
fread(databuf,1,640,infile);
i = 0;
switch(choice)
{
case '1': /* PLOT POINTS, 2 pages */
loadcolors();
fline = 0;
while(fread(databuf,1,640,infile))
{
flipcpu(); /* DRAW ON UNDISPLAYED PAGE */
clrscr();
locate(25,75);
printf("%d",++fline);
for(x = 0 ; x < 640 ; x++)
{
y = 224 - (int)((((double)(databuf[x])) - lowy) * yfactor);
pset(x,y,colors[(int)(databuf[x])-1]);
}
flipcrtc(); /* SHOW THE PAGE WE JUST DREW */
if(csts() == 3) /* ^C ABORTS */
break;
if(skip) /* eof ok, will just */
for(j = 0 ; j < skip ; j++, fline++) /* exit on next pass */
fread(databuf,1,640,infile);
}
break;
case '2': /* overlay points, 1 page */
fline = 0;
color = 0;
while(fread(databuf,1,640,infile))
{
if(color == sccount)
color = 0;
locate(25,75);
printf("%d",++fline);
for(x = 0 ; x < 640 ; x++)
{
y = 224 - (int)((((double)(databuf[x])) - lowy) * yfactor);
pset(x,y,scrcolors[color]);
}
color++;
if(csts() == 3) /* ^C ABORTS */
break;
if(skip)
for(j = 0 ; j < skip ; j++, fline++)
fread(databuf,1,640,infile);
}
zedsave();
break;
case '3': /* LINES, 2 pages */
loadcolors();
fline = 0;
while(fread(databuf,1,640,infile))
{
flipcpu();
clrscr();
locate(25,75);
printf("%d",++fline);
lastx = 0;
lasty = 224 - (int)((((double)(databuf[0])) - lowy) * yfactor);
for(x = 0 ; x < 640 ; x++)
{
y = 224 - (int)((((double)(databuf[x])) - lowy) * yfactor);
line(lastx,lasty,x,y,4);
lastx = x;
lasty = y;
}
flipcrtc(); /* SHOW THE PAGE WE JUST DREW */
if(csts() == 3) /* ^C ABORTS */
break;
if(skip)
for(j = 0 ; j < skip ; j++, fline++)
fread(databuf,1,640,infile);
}
break;
case '4': /* OVERLAY LINES, 1 PAGE */
fline = 0;
color = 0;
while(fread(databuf,1,640,infile))
{
if(color == sccount)
color = 0;
locate(25,75);
printf("%d",++fline);
lastx = 0;
lasty = 224 - (int)((((double)(databuf[0])) - lowy) * yfactor);
for(x = 0 ; x < 640 ; x++)
{
y = 224 - (int)((((double)(databuf[x])) - lowy) * yfactor);
line(lastx,lasty,x,y,scrcolors[color]);
lastx = x;
lasty = y;
}
color++;
if(csts() == 3) /* ^C ABORTS */
break;
if(skip)
for(j = 0 ; j < skip ; j++, fline++)
fread(databuf,1,640,infile);
}
zedsave();
break;
case '5': /* FILL AREAS, color = height, from file */
loadcolors();
fline = 0;
while(fread(databuf,1,640,infile))
{
locate(25,75);
printf("%d",++fline);
for(x = 0 ; x < 640 ; x++)
{
y = 224 - (int)((((double)(databuf[x])) - lowy) * yfactor);
line(x,y,x,224,colors[(int)(databuf[x])-1]);
}
if(csts() == 3) /* ^C ABORTS */
break;
if(skip)
for(j = 0 ; j < skip ; j++, fline++)
fread(databuf,1,640,infile);
}
zedsave();
break;
case '6': /* FILL AREAS, color = nearness, colors rotated */
color = 0; /* USED (IN THIS ROUTINE ONLY) AS AN INDEX */
fline = 0;
while(fread(databuf,1,640,infile))
{
locate(25,75);
printf("%d",++fline);
if(color == sccount)
color = 0;
for(x = 0 ; x < 640 ; x++)
{
y = 224 - (int)((((double)(databuf[x])) - lowy) * yfactor);
line(x,y,x,224,scrcolors[color]);
}
color++;
if(csts() == 3) /* ^C ABORTS */
break;
if(skip)
for(j = 0 ; j < skip ; j++, fline++)
fread(databuf,1,640,infile);
}
zedsave();
break;
} /* END SWITCH */
fclose(infile);
restorepg1();
puts("\033z");
exit(0);
}
|
|
|
|
|
|
|
Copyright ©2011 Steven Whitney. Last modified Tue 05/24/2011 12:27:49 -0700. |
||