Caco-2 cell permeability assay for drug absorption
Fractal proj report 2
1. 1
INTRODUCTION
Fractal definition: According to Mandelbrot (the one who coined the term
fractal), fractal is a rough or fragmented geometric shape that can be split
into parts, each of which is (at least approximately) reduced-sized copy of
the whole. They are made by repeating a process. Fractals are found
everywhere around us in nature. Ferns, rocky coastline, seashells, galaxies,
branching of blood vessels, lightning are a few examples.
My fascination for fractals was aroused when I got the book "Chaos" by
James Gleick. Fractal is an amazing topic which combines maths and art.
Beautiful patterns are generated from simple iterative functions. I decided
that for my class 12 project, I should try and recreate certain fractals using
my current C++ knowledge. In this project, I have made burning ship fractal,
Barnsley fern, Julia set, Mandelbrot set, Newton's fractal and Sierpinski
triangle. Each fractal is based on different algorithms. I have made
separate functions (by the name of the fractal) for each of the fractals. A
separate program was written to write information and history of each
fractal into a text file. Further, I have added an option were the user can
enter the zoom values and explore the fractals more. The parameters
entered to draw and zoom the fractals are stored in binary files. Along with
making the fractal images, I have made a function which tracks the path
followed by a point when it is successively iterated under the given function.
I have included the output when the entire program is run sequentially that
is all the fractals are displayed one after the other. Towards the end, the
user may insert, delete or modify certain parameters (these tasks are
implemented by file handling). All the parameters entered are then
displayed.
I enjoyed the challenge of writing the code and the beautiful outputs that I
got.
2. 2
Code
#include<fstream.h> //file handling
#include<conio.h>
#include<graphics.h>
#include<math.h> //sin, fabs, abs
#include<complex.h> //complex r(real, imaginary)
#include<stdlib.h> //rand()
#include<dos.h> //delay(milliseconds)
#include<stdio.h> //puts(string)
double pi=3.1415926536;
//NOTE: ALL THE FRACTAL IMAGES ARE REVERSED UPSIDE DOWN AS IN C++, y AXIS IS
POSITIVE DOWNWARDS
int w=639,h=479;
//julia
double cre_j=-0.7, cim_j=0.27015;
double newre_j,newim_j,oldre_j,oldim_j;
double zoom_j=1, X_j=0, Y_j=0;
int max_it_j=300;
//mandelbrot
double pre_m, pim_m;
double newre_m,newim_m,oldre_m,oldim_m;
double zoom_m=1, X_m=-0.5, Y_m=0;
int max_it_m=128;
//functions
void burning_ship();
void fern();
void juliadraw(int max_it_j, double zoom_j, double X_j, double Y_j, double
cre_j, double cim_j);
void mandelbrot_zoom(int max_it_m, double zoom_m, double X_m, double Y_m);
void mandelbrot_track();
void newton();
void sier_gask();
void filehandling_menu()
{
cout<<"n1. Insert parameters ";
cout<<"n2. Delete parameters ";
cout<<"n3. Modify parameters ";
cout<<"n4. Exit ";
}
class julia
{
public:
int max_it_j;
double X_j, Y_j, cre_j, cim_j, zoom_j;
3. 3
void getjuliainfo(char draw='y')
{
cout<<"Enter zoom value"; cin>>zoom_j;
cout<<"Enter x coordinate"; cin>>X_j;
cout<<"Enter y coordinate"; cin>>Y_j;
cout<<"Enter real part of c"; cin>>cre_j;
cout<<"enter imaginary part of c"; cin>>cim_j;
cout<<"enter max iterations"; cin>>max_it_j;
if(draw=='y')
{
juliadraw(max_it_j, zoom_j, X_j, Y_j, cre_j, cim_j);
}
}
void putjuliainfo()
{
cout<<"nZoom : "<<zoom_j;
cout<<"nx coordinate : "<<X_j;
cout<<"ny coordinate : "<<Y_j;
cout<<"nreal part of c : "<<cre_j;
cout<<"nimaginary part of c : "<<cim_j;
cout<<"nIterations : "<<max_it_j;
}
}Julia;
void displayjuliainfo()
{
cout<<"nJULIA PARAMETERS ENTERED BY YOUn";
ifstream f;
f.open("Julia.dat", ios::binary);
while(f.read((char*)&Julia, sizeof(Julia)))
{
Julia.putjuliainfo();
cout<<'n';
}
f.close();
}
void createjuliainfo()
{
juliadraw(max_it_j, zoom_j, X_j, Y_j, cre_j, cim_j);
ofstream f;
f.open("Julia.dat", ios::binary);
char choice='y';
cout<<"Do you want to zoom (y/n)? "; cin>>choice;
for(;choice!='n';)
{
Julia.getjuliainfo();
f.write((char*)&Julia, sizeof(Julia));
cout<<"Do you want to zoom (y/n) ";
cin>>choice;
}
f.close();
}
void Insertjuliaparameters()
{
ofstream f;
f.open("Julia.dat", ios::app|ios::nocreate);
4. 4
Julia.getjuliainfo('n');
f.write((char*)&Julia, sizeof(Julia));
f.close();
}
void Deletejuliaparameters()
{
int i=0, n;
cout<<"Which record do you want to delete (n value)? ";
cin>>n;
ifstream f;
ofstream ft;
f.open("Julia.dat", ios::binary);
ft.open("temp.dat", ios::binary);
while(f.read((char*)&Julia, sizeof(Julia)))
{
if(i==n-1)
{} //delete this record
else
ft.write((char*)&Julia, sizeof(Julia));
i++;
}
f.close();
ft.close();
remove("Julia.dat");
rename("temp.dat", "Julia.dat");
}
void Modifyjuliaparameters()
{
fstream f;
f.open("Julia.dat", ios::in|ios::out|ios::binary);
int n, i=0;
cout<<"Which record do you want to modify (n value)? ";
cin>>n;
long pos;
while(!f.eof())
{
pos=f.tellg(); //determine beginning pos of record
f.read((char*)&Julia, sizeof(Julia));
if(i==n-1) //this record is to be modified
{
Julia.getjuliainfo('n');
f.seekg(pos);
f.write((char*)&Julia, sizeof(Julia));
break;
}
if(f.eof()) break;
i++;
}
}
15. 15
int v1[2]={10,10};
int v2[2]={510,10};
int v3[3]={260,sqrt(3)*250}; //vertices
int vertex;
int newx,newy;
int x=rand()%600+10;
int y=rand()%400+10;
for(long int i=0;i<900000;i++)
{
vertex=rand()%3+1;
if(vertex==1)
{
newx=(x+v1[0])/2;
newy=(y+v1[1])/2;
putpixel(newx,newy,15);
}
if(vertex==2)
{
newx=(x+v2[0])/2;
newy=(y+v2[1])/2;
putpixel(newx,newy,15);
}
if(vertex==3)
{
newx=(x+v3[0])/2;
newy=(y+v3[1])/2;
putpixel(newx,newy,15);
}
x=newx;
y=newy;
}
}
16. 16
Separate program to write history and information
of each fractal into a text file
#include<fstream.h>
#include<conio.h>
#include<stdio.h>
void create()
{
ofstream f;
f.open("fractal_history.txt");
int i=0;
char l[200];
for(i=0;i<25;i++)
{
gets(l);
f<<l<<endl;
}
f.close();
}
void display()
{
char l[200];
ifstream f;
f.open("fractal_history.txt");
while(f.getline(l,200))
{
puts(l);
}
f.close();
}
void main()
{
clrscr();
create();
display();
getch();
}