Tu znajdziesz dane do wykorzystania w poniższym programie i pliki do ściągnięcia.

 

PROGRAM 01 Program w języku C++

 

/*
IMAGE.C images By Roger T. Stevens 31-10-90r.
Program do przedstawiania (IFS) iteracyjnych funkcji postaci:
X(n+1) = Ai Xn + Bi Yn+ Ei
Y(n+1) = Ci Xn + Di Yn+ Fi
Dane dla tych funkcji są pobierane z pliku. Przykładowy plik może wyglądać tak:
3
0.5# 0.0# 0.0# 0.5# 0.0# 0.0# 0.3333#
0.5# 0.0# 0.0# 0.5# 1.0# 0.0# 0.3333#
0.5# 0.0# 0.0# 0.5# 0.5# 0.5# 0.3333#
Trójkąt Sierpińskiego
*/
#include<stdio.h>
#include<math.h>
#include<dos.h>
#include<conio.h>
#include<stdlib.h>
void cls(int color);
void get_string(char string_buf[]);
void image_draw(int color);
void plots(int x, int y, int color);
void plot(int x, int y, int color);
void setMode(int mode);
int LINEWIDTH,OPERATOR,XCENTER,YCENTER,ANGLE;
unsigned long int PATTERN;
int adapt,mode,no_transformations,flag;
int j, k, temp, xoffset,yoffset,pr,p_cum[128];
long unsigned int i;
float a[128],b[128],c[128],d[128],e[128],f[128],p[128],p_sum,x,y,
newx, xmax, xmin, ymax, ymin, xscale, yscale;
char ch, filename[13], buffer[64];
int color, background;
FILE *fin;
void main(void)
{
for(;;)
{
setMode(3);
window(1,1,80,24);
textbackground(0);
clrscr();
window(10,8,60,15);
textbackground(1);
clrscr();
textcolor(15);
cprintf(" Nacisnij 'Enter' by uruchomic fraktal,\n");
gotoxy(6,2);
cprintf("dowolny klawisz to wyjscie... ");
cscanf("%c",&ch);
if (ch !=0x0d)
break;
cprintf("\n Podaj nazwe pliku :");
cscanf("%s",filename);
fin = fopen(filename,"rb");
if (fin == NULL)
{
cprintf("\n Pliku '%s' nie ma.",filename);
getch();
getch();
break;
}
cprintf("\n Wybierz kolor tla (0-15): ");
cscanf("%d",&background);
cprintf("\n Wybierz kolor grafiki (0-15): ");
cscanf("%d",&color);
get_string(buffer);
no_transformations = atoi(buffer);
if ((strstr(filename,".ifs")) != NULL)
{
for (i=0; i<6; i++)
get_string(buffer);
}
for (i=0; i<no_transformations; i++)
{
get_string(buffer);
a[i] = atof(buffer);
get_string(buffer);
b[i] = atof(buffer);
get_string(buffer);
c[i] = atof(buffer);
get_string(buffer);
d[i] = atof(buffer);
get_string(buffer);
e[i] = atof(buffer);
get_string(buffer);
f[i] = atof(buffer);
get_string(buffer);
p[i] = atof(buffer);
if ((strstr(filename,".ifs")) != NULL)
{
get_string(buffer);
get_string(buffer);
}
}
fclose(fin);
setMode(16);
p_sum = 0;
for (i=0; i<no_transformations; i++)
{
p_sum += p[i];
p_cum[i] = p_sum * 32767;
}
cls (background);
image_draw(color);
getch();
getch();
}
}
/* -------------------------------------------------------
Image_draw() = Funcja rysująca obraz IFS
-------------------------------------------------------- */
void image_draw(int color)
{
int px,py;
xmax = 0;
ymax = 0;
xmin = 0;
ymin = 0;
x = 0;
y = 0;
flag = 0;
while (!kbhit())
{
for (i=0; i<256; i++)
{
temp = rand();
for (k=0; k<no_transformations-1; k++)
{
if (temp < p_cum[k])
break;
}
newx = (a[k]* x + b[k] * y + e[k]);
y = (c[k] * x + d[k] * y + f[k]);
x = newx;
if ((flag == 0) && (i>15))
{
xmax = max(x,xmax);
xmin = min(x,xmin);
ymax = max(y,ymax);
ymin = min(y,ymin);
}
else
{
px = x*xscale + xoffset;
py = (y*yscale + yoffset);
if ((px>=0) && (px<639) && (py>=0) && (py<349))
plot (px,349-py,color);
}
}
if (flag == 0)
{
xscale = 418 / (xmax - xmin);
yscale = min(315 / (ymax - ymin),xscale/1.38);
if (yscale < xscale/1.38);
xscale = 1.38 * yscale;
xoffset = 320 - (xmax + xmin) * xscale / 2;
yoffset = 175 - (ymax + ymin) * yscale / 2;
flag = 1;
}
}
}
/* ------------------------------------------------------------------
cls() = Czyszczenie ekranu.
---------------------------------------------------------------------*/
void cls(int color)
{
union REGS reg;
reg.x.ax = 0x0600;
reg.x.cx = 0;
reg.x.dx = 0x184F;
reg.h.bh = color;
int86(0x10,&reg,&reg);
}
/* -----------------------------------------------------------------------------
plot() = Plots a poin on the screen at designated system coordinates
using a selected color.
-----------------------------------------------------------------------------*/
void plot(int x, int y, int color)
{
#include<dos.h>
#define seq_out(index,val) {outp(0x3C4,index);\
outp(0x3C5,val);}
#define graph_out(index,val) {outp(0x3CE,index);\
outp(0x3CF,val);}
unsigned int offset;
int dummy,mask,page;
char far * mem_address;
offset = (long)y * 80L + ((long)x / 8L);
mem_address = (char far *) 0xA0000000L + offset;
mask = 0x80 >> (x % 8);
graph_out(8,mask);
seq_out(2,0x0F);
dummy = *mem_address;
*mem_address = 0;
seq_out(2,color);
*mem_address = 0xFF;
seq_out(2,0x0F);
graph_out(3,0);
graph_out(8,0xFF);
}
/* --------------------------------------------------------
setMode() = Ustawia tryb wideo
-------------------------------------------------------- */
void setMode(int mode)
{
union REGS reg;
reg.h.ah = 0;
reg.h.al = mode;
int86 (0x10,&reg,&reg);
}
/* -----------------------------------------------------------------
get_string() = Czyta wartości zawarte w otwartym pliku
----------------------------------------------------------------- */
void get_string(char string_buf[])
{
char ch;
int flag = 0,i,result,test;
string_buf[0] = NULL;
while (!feof(fin))
{
ch = toupper(fgetc(fin));
if (flag == 0)
{
if ((isalnum(ch)) || (ch == '.') || (ch == '-') ||
(ch == ')'))
{
string_buf[0] = ch;
break;
}
else
{
if (ch == '#')
flag = 1;
}
}
else
if (ch == 0x0D)
flag = 0;
}
for (i=1; i<32; i++)
{
if (ch == ')')
{
string_buf[1] = NULL;
break;
}
ch = toupper(fgetc(fin));
if ((isalnum(ch)) || (ch == '_') || (ch == '.'))
string_buf[i] = ch;
else
{
string_buf[i] = NULL;
break;
}
}
}