What is a Fractal?
- A fractal is a never-ending pattern
===========================================================================
CODING
#include<iostream.h>
#include<conio.h>
#include<dos.h>
#include<process.h>
#include<stdio.h>
#include<math.h>
char STR[51][161];
void Fill_String();
void Print(int x,int y);
void Background_Clear();
void main()
{
textbackground(1);
clrscr();
char a;
int x,y;
// Background_Clear();
Fill_String();
x=0;
y=0;
while(1==1)
{
Print(x,y);
a=getch();
if(a=='d' || a=='D')
{
if(x<82)
x++;
}
else if(a=='w' || a=='W')
{
if(y>0)
y--;
}
else if(a=='a' || a=='A')
{
if(x>0)
x--;
}
else if(a=='s' || a=='S')
{
if(y<30)
y++;
}
else if(a==27)
exit(0);
}
}
void Fill_String()
{
sprintf(STR[0]," ");
sprintf(STR[1]," ");
sprintf(STR[2]," ");
sprintf(STR[3]," ");
sprintf(STR[4]," ");
sprintf(STR[5]," ");
sprintf(STR[6]," ");
sprintf(STR[7]," ");
sprintf(STR[8]," ");
sprintf(STR[9]," ");
sprintf(STR[10]," ");
sprintf(STR[11]," ");
sprintf(STR[12]," ");
sprintf(STR[13]," ");
sprintf(STR[14]," ");
sprintf(STR[15]," ");
sprintf(STR[16]," ");
sprintf(STR[17]," ");
sprintf(STR[18]," ");
sprintf(STR[19]," ");
sprintf(STR[20]," ");
sprintf(STR[21]," ");
sprintf(STR[22]," ");
sprintf(STR[23]," ");
sprintf(STR[24]," ");
sprintf(STR[25]," ");
sprintf(STR[26]," ");
sprintf(STR[27]," ");
sprintf(STR[28]," ");
sprintf(STR[29]," ");
sprintf(STR[30]," ");
sprintf(STR[31]," ");
sprintf(STR[32]," ");
sprintf(STR[33]," ");
sprintf(STR[34]," ");
sprintf(STR[35]," ");
sprintf(STR[36]," ");
sprintf(STR[37]," ");
sprintf(STR[38]," ");
sprintf(STR[39]," ");
sprintf(STR[40]," ");
sprintf(STR[41]," ");
sprintf(STR[42]," ");
sprintf(STR[43]," ");
sprintf(STR[44]," ");
sprintf(STR[45]," ");
sprintf(STR[46]," ");
sprintf(STR[47]," ");
sprintf(STR[48]," ");
sprintf(STR[49]," ");
sprintf(STR[50]," ");
sprintf(STR[51]," ");
double rc,ic,iz,rz,rz1,iz1,i,j,a,k,x,y;
for(i=1;i>=-1;i=i-0.04)
{
for(j=1;j>=-2;j=j-0.01875)
{
rc=j;
ic=i;
for(rz=iz=0,k=0;k<=100;k++)
{
if(kbhit())
exit(0);
rz1=rz*rz-iz*iz+rc;
iz1=2*rz*iz+ic;
if(abs(rz1)>=2 || abs(iz1)>=2)
break;
rz=rz1;
iz=iz1;
}
// if(abs(rz1)<2)
// {
x=106.6666+rc*53.3333+1;
y=25-ic*25+1;
if(k<=10)
STR[y][x]='.';
else if(k<=20)
STR[y][x]='_';
else if(k<=30)
STR[y][x]='-';
else if(k<=40)
STR[y][x]='=';
else if(k<=50)
STR[y][x]='#';
else if(k<=60)
STR[y][x]='[';
else if(k<=70)
STR[y][x]=']';
else if(k<=80)
STR[y][x]='*';
else if(k<=90)
STR[y][x]='&';
else if(k<=100)
STR[y][x]='Û';
// }
}
}
}
void Print(int x,int y)
{
int i,j;
for(i=2;i<=79;i++)
{
for(j=2;j<=24;j++)
{
gotoxy(i,j);
if(STR[y+j-2][x+i-2]=='.')
{
textcolor(11);
cprintf("Û");
}
else if(STR[y+j-2][x+i-2]=='_')
{
textcolor(3);
cprintf("Û");
}
else if(STR[y+j-2][x+i-2]=='-')
{
textcolor(9);
cprintf("Û");
}
else if(STR[y+j-2][x+i-2]=='=')
{
textcolor(10);
cprintf("Û");
}
else if(STR[y+j-2][x+i-2]=='#')
{
textcolor(14);
cprintf("Û");
}
else if(STR[y+j-2][x+i-2]=='[')
{
textcolor(13);
cprintf("Û");
}
else if(STR[y+j-2][x+i-2]==']')
{
textcolor(5);
cprintf("Û");
}
else if(STR[y+j-2][x+i-2]=='*')
{
textcolor(12);
cprintf("Û");
}
else if(STR[y+j-2][x+i-2]=='&')
{
textcolor(4);
cprintf("Û");
}
else if(STR[y+j-2][x+i-2]=='Û')
{
textcolor(0);
cprintf("Û");
}
else
{
textcolor(0);
cprintf("Û");
}
}
}
}
void Background_Clear()
{
int i,j;
textbackground(0);
for(i=2;i<=79;i++)
for(j=2;j<=24;j++)
{
gotoxy(i,j);
cprintf(" ");
}
}
CODING
#include<iostream.h>
#include<conio.h>
#include<dos.h>
#include<process.h>
#include<stdio.h>
#include<math.h>
char STR[51][161];
void Fill_String();
void Print(int x,int y);
void Background_Clear();
void main()
{
textbackground(1);
clrscr();
char a;
int x,y;
// Background_Clear();
Fill_String();
x=0;
y=0;
while(1==1)
{
Print(x,y);
a=getch();
if(a=='d' || a=='D')
{
if(x<82)
x++;
}
else if(a=='w' || a=='W')
{
if(y>0)
y--;
}
else if(a=='a' || a=='A')
{
if(x>0)
x--;
}
else if(a=='s' || a=='S')
{
if(y<30)
y++;
}
else if(a==27)
exit(0);
}
}
void Fill_String()
{
sprintf(STR[0]," ");
sprintf(STR[1]," ");
sprintf(STR[2]," ");
sprintf(STR[3]," ");
sprintf(STR[4]," ");
sprintf(STR[5]," ");
sprintf(STR[6]," ");
sprintf(STR[7]," ");
sprintf(STR[8]," ");
sprintf(STR[9]," ");
sprintf(STR[10]," ");
sprintf(STR[11]," ");
sprintf(STR[12]," ");
sprintf(STR[13]," ");
sprintf(STR[14]," ");
sprintf(STR[15]," ");
sprintf(STR[16]," ");
sprintf(STR[17]," ");
sprintf(STR[18]," ");
sprintf(STR[19]," ");
sprintf(STR[20]," ");
sprintf(STR[21]," ");
sprintf(STR[22]," ");
sprintf(STR[23]," ");
sprintf(STR[24]," ");
sprintf(STR[25]," ");
sprintf(STR[26]," ");
sprintf(STR[27]," ");
sprintf(STR[28]," ");
sprintf(STR[29]," ");
sprintf(STR[30]," ");
sprintf(STR[31]," ");
sprintf(STR[32]," ");
sprintf(STR[33]," ");
sprintf(STR[34]," ");
sprintf(STR[35]," ");
sprintf(STR[36]," ");
sprintf(STR[37]," ");
sprintf(STR[38]," ");
sprintf(STR[39]," ");
sprintf(STR[40]," ");
sprintf(STR[41]," ");
sprintf(STR[42]," ");
sprintf(STR[43]," ");
sprintf(STR[44]," ");
sprintf(STR[45]," ");
sprintf(STR[46]," ");
sprintf(STR[47]," ");
sprintf(STR[48]," ");
sprintf(STR[49]," ");
sprintf(STR[50]," ");
sprintf(STR[51]," ");
double rc,ic,iz,rz,rz1,iz1,i,j,a,k,x,y;
for(i=1;i>=-1;i=i-0.04)
{
for(j=1;j>=-2;j=j-0.01875)
{
rc=j;
ic=i;
for(rz=iz=0,k=0;k<=100;k++)
{
if(kbhit())
exit(0);
rz1=rz*rz-iz*iz+rc;
iz1=2*rz*iz+ic;
if(abs(rz1)>=2 || abs(iz1)>=2)
break;
rz=rz1;
iz=iz1;
}
// if(abs(rz1)<2)
// {
x=106.6666+rc*53.3333+1;
y=25-ic*25+1;
if(k<=10)
STR[y][x]='.';
else if(k<=20)
STR[y][x]='_';
else if(k<=30)
STR[y][x]='-';
else if(k<=40)
STR[y][x]='=';
else if(k<=50)
STR[y][x]='#';
else if(k<=60)
STR[y][x]='[';
else if(k<=70)
STR[y][x]=']';
else if(k<=80)
STR[y][x]='*';
else if(k<=90)
STR[y][x]='&';
else if(k<=100)
STR[y][x]='Û';
// }
}
}
}
void Print(int x,int y)
{
int i,j;
for(i=2;i<=79;i++)
{
for(j=2;j<=24;j++)
{
gotoxy(i,j);
if(STR[y+j-2][x+i-2]=='.')
{
textcolor(11);
cprintf("Û");
}
else if(STR[y+j-2][x+i-2]=='_')
{
textcolor(3);
cprintf("Û");
}
else if(STR[y+j-2][x+i-2]=='-')
{
textcolor(9);
cprintf("Û");
}
else if(STR[y+j-2][x+i-2]=='=')
{
textcolor(10);
cprintf("Û");
}
else if(STR[y+j-2][x+i-2]=='#')
{
textcolor(14);
cprintf("Û");
}
else if(STR[y+j-2][x+i-2]=='[')
{
textcolor(13);
cprintf("Û");
}
else if(STR[y+j-2][x+i-2]==']')
{
textcolor(5);
cprintf("Û");
}
else if(STR[y+j-2][x+i-2]=='*')
{
textcolor(12);
cprintf("Û");
}
else if(STR[y+j-2][x+i-2]=='&')
{
textcolor(4);
cprintf("Û");
}
else if(STR[y+j-2][x+i-2]=='Û')
{
textcolor(0);
cprintf("Û");
}
else
{
textcolor(0);
cprintf("Û");
}
}
}
}
void Background_Clear()
{
int i,j;
textbackground(0);
for(i=2;i<=79;i++)
for(j=2;j<=24;j++)
{
gotoxy(i,j);
cprintf(" ");
}
}
===========================================================================
No comments:
Post a Comment