cg report.docx

44
1 ANNA UNIVERSITY: CHENNAI CS2405 COMPUTER GRAPHICSLAB GENERATION OF VOLUMETRIC ESCAPE TIME FRACTALS MINI PROJECT REPORT SUBMITTED BY , S.RAJA PRABHA [951712205036] S.SINDHU PARKAVI [951712205049] C.VAISHNAVI [951712205061] DEPARTMENT OF INFORMATION TECHNOLOGY MEPCO SCHLENK ENGINEERING COLLEGE

Upload: adalberto-macdonald

Post on 24-Jan-2016

259 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: cg report.docx

1

ANNA UNIVERSITY: CHENNAI

CS2405 COMPUTER GRAPHICSLAB

GENERATION OF VOLUMETRIC ESCAPE TIME FRACTALS

MINI PROJECT REPORT

SUBMITTED BY ,

S.RAJA PRABHA [951712205036]

S.SINDHU PARKAVI [951712205049]

C.VAISHNAVI [951712205061]

DEPARTMENT OF INFORMATION TECHNOLOGY

MEPCO SCHLENK ENGINEERING COLLEGE

MEPCO NAGAR, SIVAKASI.

2015-2016

Page 2: cg report.docx

2

CERTIFICATE

This is to Certify that it is the bonafide work done by S.RAJA

PRABHA,S.SINDHU PARKVAI and C.VAISHNAVI for their Mini Project

on GENERATION OF VOLUMETRIC ESCAPE TIME FRACTALS in

the CS2405 COMPUTER GRAPHICS LAB at Mepco Schlenk Engineering

College, Sivakasi during the year 2015-2016.

.………………… …………………………

Staff in charge Head of the Department

Page 3: cg report.docx

3

ACKNOWLEDGEMENT

We have taken efforts in this project. However, it would not have been possible

without the kind support and help of many individuals and our reputed

institution Mepco Schlenk Engineering College, Sivakasi. We would like to

extend our sincere thanks to our Principal Dr. S. Arivazhagan ME., PhD.

We would like to express my special gratitude and thanks to Dr.T.Revathi ME.,

PhD. Senior Professor & Head of the Department for giving us such a

wonderful experience.

We are highly indebted to, Mrs.R.Venitta Raj AP(Sr.Grade)/IT ,

Mr.B.D.Deebak AP/IT for their guidance and constant supervision as well as for

providing necessary information regarding the project & also for their support

in completing the project.

We would like to express our gratitude towards our parents and members of IT

Department of this prestigious institution for their kind co-operation and

encouragement which help us in completion of this project.

Page 4: cg report.docx

4

ABSTRACT

Generation of volumetric Escape time fractals is to create solid fractals, It uses

quaternion representations for transforming points in three or four dimension. It

is an extension of complex function transformation of analysis and rendering. It

relies on iterative mathematical calculations. It forms the volumetric cloud of

points with values corresponding to escape time at certain position in three

dimensional space. This algorithm is very fast and can handle shapes with caves

and holes, which is important in fractal objects. These fractals are used in

interactive fractal presentation and magnification on cell phones equipped with

the Java-language programming environment.

Page 5: cg report.docx

5

TABLE OF CONTENTS

1.Program statement 6

2.Program Description 7

3.Language Used 8

4. Algorithm 12

5. Procedure 19

6. Code 23

7.ScreenShots 37

8.Conclusion 38

Page 6: cg report.docx

6

PROGRAM STATEMENT

The implementation of escape time fractals relies on iterative

mathematical calculations. In particular, the method is based on

monitoring the number of iterations necessary to determine whether an

orbit sequence tends to infinity or not. One of the most popular

approaches is to use nonlinear equations with chaotic solutions. The

solutions are most interesting if they involve at least two variables x and

y, which can be used to represent horizontal and vertical positions on a

graphics screen. With complex numbers, used in equations where x and

yare elements of the complex number z, the simplest andmost popular

equation used as an example is z =z^2 + c;where c is a complex constant.

This way we can render the most popular escape-time fractals such

asMandelbrot and Julia sets Interestingly, these kinds of fractals have

become so popular that interactive fractal presentation and magnification

is now possible on cell phones equipped with the Java-language

programming environment. One such example is mFrac, a distributed

fractal explorer for mobile devices such as phones and PDAs.

Page 7: cg report.docx

7

PROGRAM DESCRIPTION

A combination of linear and quadratic functions may be used toproduce

fractal forms with a beautiful and visually balanced shape.Therefore, we

decided to extend previous methods to the third dimension.2-D algorithms are

observed to be visually appealing fractals often occur when the orbit

‘‘slowly’’escapes to infinity. The same rule can be applied to solids. In a similar

manner, we start by choosing 30 coefficients of the generalized function

limiting ourselves to the simplest nonlineraties.

Page 8: cg report.docx

8

LANGUAGE USED

OPENGL:

The OpenGL graphics system is a software interface to graphics hardware.

(“GL” stands for “Graphics Library.”) It allows you to create interactive

programs that produce color images of moving, three dimensional objects.

With OpenGL, you can control computer-graphics technology to produce

realistic pictures, or ones that depart from reality in imaginative ways. OpenGL

is a software interface to graphics hardware.

This interface consists of more than 700 distinct commands (about 670

commands as specified for OpenGL Version 3.0 and another 50 in the OpenGL

Utility Library) that you use to specify the objects and operations needed to

produce interactive three-dimensional applications. OpenGL is designed as a

streamlined, hardware-independent interface to be implemented on many

different hardware platforms. To achieve these qualities, no commands for

performing windowing tasks or obtaining user input are included in OpenGL;

instead, you must work through whatever windowingsystem controls the

particular hardware you’re using. Similarly,OpenGL doesn’t provide high-level

commands for describing models of three-dimensional objects. Such commands

might allow you to specify relatively complicated shapes such as automobiles,

parts of the body, airplanes, or molecules. With OpenGL, you must build your

desired model from a small set of geometric primitives—points, lines, and

Page 9: cg report.docx

9

polygons. The OpenGL specification describes an abstract API for drawing 2D

and 3D graphics. Although it is possible for the API to be implemented entirely

in software, it is designed to be implemented mostly or entirely in hardware.

A sophisticated library that provides these features could certainly be built on

top of OpenGL. The OpenGL Utility Library (GLU) provides many of the

modeling features, such as quadric surfaces and NURBS curves and surfaces.

GLU is a standard part of every OpenGL implementation.

HEADER FILES

In Windows we need to include the gl.h header for OpenGL 1.1 support and

link against OpenGL32.lib. Both are a part of the Windows SDK. In addition,

you might want the headers wglext.h and glext.h which you can get

from http://www.opengl.org/registry .wglext.h has typedefs for Windows-

specific extensions, and glext.h is the header which holds mostly platform-

agnostic extensions and OpenGL core functionality which is later than OpenGL

version 1.1.

Linux

On Linux you need to link against libGL.so, which is usually a symlink to

libGL.so.1, which is yet a symlink to the actual library/driver which is a part of

your graphics driver. For example, on my system the actual driver library is

named libGL.so.256.53, which is the version number of the nvidia driver I use.

Page 10: cg report.docx

10

You also need to include the gl.h header, which is usually a part of a Mesa or

Xorg package. Again, you might

need glext.h and glxext.h from http://www.opengl.org/registry . glxext.h holds

GLX extensions, the equivalent to wglext.h on Windows.

If you want to use OpenGL 3.x or OpenGL 4.x functionality without the

functionality which were moved into the GL_ARB_compatibility extension, use

the new gl3.h header from the registry webpage. It replaces gl.h and

also glext.h (as long as you only need core functionality).

Last but not the least, glaux.h is not a header associated with OpenGL. I assume

you've read the awful NEHE tutorials and just went along with it. Glaux is a

horribly outdated Win32 library (1996) for loading uncompressed bitmaps. Use

something better, like libPNG, which also supports alpha channels.

DRAWING POINTS

OpenGL has the command glBegin(glPoints) to plot the points. GlVertex2f(x,y)

and GLVertex3f(x,y,z) are the ways to plot 2D and 3D points on the console.

FRACTALS

A fractal is a natural phenomenon or a mathematical set that exhibits a

repeating pattern that displays at every scale. If the replication is exactly the

same at every scale, it is called a self-similar pattern.

Page 11: cg report.docx

11

ALGORITHM:

{Pseudocode illustrate method for generating EscapeTime fractals}

{built with ‘‘3-D points’’}

program fractals;

const

MaxColors=80; {Numbers of layers in 3-D}

{ variables }

var

x, y, z : Real; { current point in fractal space }

a : array [0..29] of Real; { fractal code (fractal coefficients) }

fDimX, fDimY, fDimZ : Real; { dimensions of fractal space (e.g.=8.0f) }

iSizeX, iSizeY, iSizeZ : Integer; { e.g.=300, 3D dimensions of solid }

fScaleX, fScaleY, fScaleZ : Real; { scales of dimensions (e.g.=4.0f) }

n : Integer; { a color/layer of a point }

iKernelColor : Integer; { a threshold color; i.e. the number of the first

Page 12: cg report.docx

12

visible layer of a fractal (e.g.=5). Layers are

numbered from 0 }

iMaxBound : Integer; { e.g.=1000 }

fMaxSolution : Real; { e.g.=1000000.0f }

{ Calculate current solution for x, y and z. Increment. }

procedure AdvanceXY;

var

xnew, ynew : Real;

begin

xnew:¼a[0]+x_a[1]+y_a[2]+z_a[3]+

x_x_a[4]+y_y_a[5]+z_z_a[6]+

x_y_a[7]+x_z_a[8]+y_z_a[9];

ynew:¼a[10]+x_a[11]+y_a[12]+z_a[13]+

x_x_a[14]+y_y_a[15]+z_z_a[16]+

x_y_a[17]+x_z_a[18]+y_z_a[19];

Page 13: cg report.docx

13

z:¼a[20]+x_a[21]+y_a[22]+z_a[23]+

x_x_a[24]+y_y_a[25]+z_z_a[26]+

x_y_a[27]+x_z_a[28]+y_z_a[29];

x:¼xnew;

y:¼ynew;

n:¼n+1;

end;

{ Generates points of fractal. Display. }

procedure GeneratePoints;

var

k, i, j : Integer;

fScreenX, fScreenY, fScreenZ : Real;

begin

fWidthDiv:¼iWidth/fScaleX; fHeightDiv:¼iHeight/fScaleY;

fDepthDiv:¼iDepth/fScaleZ;

Page 14: cg report.docx

14

for k:¼0 to iSizeZ do

for i:¼0 to iSizeX do

for j:¼0 to iSizeY do

begin

x:¼fDimX+i/fWidthDiv;

y:¼fDimY_j/fHeightDiv;

z:¼fDimZ_k/fDepthDiv;

n:¼0;

while (noMaxColors) and ((x_x+y_y+z_z)ofMaxSolution) do

AdvanceXY;

{ render only one layer of fractal }

if n=iKernelColor then

begin

{ put point on screen in 3D space (centering it) }

fScreenX:¼i–iSizeX _ 0.5;

Page 15: cg report.docx

15

fScreenY:¼j–iSizeY _ 0.5;

fScreenZ:¼k_iSizeZ _ 0.5;

PutPoint3D( fScreenX, fScreenY, fScreenZ );

end;

end;

end;

{ Set parameters of a fractal (from _1.2 to 1.2). Prepare fractal environment

}

procedure SetParams;

var

i : Integer;

begin

x:¼0; y:¼0; z:¼0;

{ randomly chosen parameters }

For i:¼0 to 30 do

Page 16: cg report.docx

16

a[i]:¼(random(25)_12 )/10.0;

end;

{ Test the solution. See Pickover and Sprott for details }

procedure TestSoln;

begin

If n=iMaxBound then n:¼0; { solution is bounded }

if ( x_x+y_y+z_z )>fMaxSolution then { solution escaped }

begin

if n>100 then n:¼iMaxBound

else n:¼0;

end;

end;

begin

randomize;

{ set some initial values }

Page 17: cg report.docx

17

iSizeX :¼100; iSizeY :¼100; iSizeZ:¼100;

fDimX:¼8.0; fDimY :¼8.0; fDimZ:¼8.0;

fScaleX:¼_4.0; fScaleY:¼4.0; fScaleZ:¼4.0;

n:¼0; iKernelColor:¼6; iMaxBound:¼1000; fMaxSolution:¼1000000.0;

{ main loop }

repeat

if n=0 then SetParams;

AdvanceXY; TestSoln;

if n=iMaxBound then

begin

GeneratePoints(); n:¼0; { drawfractal }

end;

until keypressed; { loop until a key is pressed }

end

Page 18: cg report.docx

18

PROCEDURE TO CREATE OPENGL IN MICROSOFT VISUAL

STUDIO 2012

Create file -> New project

Then choose Win32 Console Application and give its name and loaction.

Page 19: cg report.docx

19

Click ok and give finish

Give next and deselect sdl and click finish.

Page 20: cg report.docx

20

In filename, right click and choose properties.

In linker choose Input and add class libraries

Page 21: cg report.docx

21

Then add opengl32.lib, glut32.lib, glu32.lib

Click Ok and type the code

Page 22: cg report.docx

22

PROGRAM CODE:

#include "stdafx.h"

#include<math.h>

#include<stdlib.h>

#include<GL/gl.h>

#include<GL/glu.h>

#include<GL/glut.h>

#include<conio.h>

const int MaxColors=80;

float x=0.0, y=0.0, z=0.0 ;

float a[30];

float fDimX=8.0, fDimY=8.0, fDimZ=8.0;

int iSizeX=40, iSizeY=40, iSizeZ=40,iDepth=140,iHeight=140,iWidth=140;

float fScaleX=-4.0, fScaleY=4.0,

fScaleZ=4.0,fWidthDiv,fHeightDiv,fDepthDiv;

Page 23: cg report.docx

23

int iKernelColor=6,iMaxBound=1000;

static int n=0;

float fMaxSolution=1000000.0;

void AdvanceXY()

{

float xnew, ynew;

xnew=a[0]+x*a[1]+y*a[2]+z*a[3]+

x*x*a[4]+y*y*a[5]+z*z*a[6]+

x*y*a[7]+x*z*a[8]+y*z*a[9];

ynew=a[10]+x*a[11]+y*a[12]+z*a[13]+

x*x*a[14]+y*y*a[15]+z*z*a[16]+

x*y*a[17]+x*z*a[18]+y*z*a[19];

z=a[20]+x*a[21]+y*a[22]+z*a[23]+

x*x*a[24]+y*y*a[25]+z*z*a[26]+

Page 24: cg report.docx

24

x*y*a[27]+x*z*a[28]+y*z*a[29];

x=xnew;

y=ynew;

printf("\n%d",n);

n=n+10;

}

void GeneratePoints()

{

int k=0, i=0, j=0;

float fScreenX, fScreenY, fScreenZ;

fWidthDiv=iWidth/fScaleX;

fHeightDiv=iHeight/fScaleY;

fDepthDiv=iDepth/fScaleZ;

for (k=0;k<=iSizeZ;k++)

{

Page 25: cg report.docx

25

printf("OUTER FOR %d ",k);

for (i=0;i<=iSizeX;i++)

{

for (j=0;j<=iSizeY;j++)

{

x=fDimX+i/fWidthDiv;

y=fDimY-j/fHeightDiv;

z=fDimZ-k/fDepthDiv;

n=0;

while ((n<MaxColors) && (((x*x)+(y*y)+(z*z))<fMaxSolution))

AdvanceXY();

if(n>=iKernelColor )

{

fScreenX=i-iSizeX * 0.5;

fScreenY=j-iSizeY * 0.5;

Page 26: cg report.docx

26

fScreenZ=k-iSizeZ * 0.5;

glBegin(GL_POINTS);

printf("\n POINTS:");

glColor3f(1.0f,0.0f,1.0f);

glVertex3f(fScreenX,fScreenY,fScreenZ);

glColor3f(0.0f,0.0f,1.0f);

printf("\nScreen inside pixel x,y,z %f %f

%f",fScreenX,fScreenY,fScreenZ);

glEnd();

glFlush();

}

}

}

}

glFlush();

}

Page 27: cg report.docx

27

void SetParams()

{

int i;

x=0; y=0; z=0;

for (i=0;i<30;i++){

float random=rand()%25;

float r=random-12.0;

//printf("\nrandom%f and %f",random,r);

a[i]=(((random)-12.0 ))/(10.0);

//printf("\nfractal%f",a[i]);

}

}

void TestSoln()

{

Page 28: cg report.docx

28

if (n==iMaxBound )

n=0;

// printf("\t X,Y,Z %d %d %d %d",x,y,z,fMaxSolution);

if (( x*x+y*y+z*z )>fMaxSolution){

if (n>100)

{

printf("\t\tFRAINMAX");

n=iMaxBound;

}

else

n=0;

}

}

void callm()

{

Page 29: cg report.docx

29

int ch=10000;

/*iSizeX =100; iSizeY =100; iSizeZ=100;

fDimX=8.0; fDimY =8.0; fDimZ=8.0;

fScaleX=-4.0; fScaleY=4.0; fScaleZ=4.0;

n=0; iKernelColor=6; iMaxBound=1000; fMaxSolution=1000000.0;*/

do

{

if (n==0)

SetParams();

AdvanceXY();

// GeneratePoints();

printf("\t%d",n);

TestSoln();

if (n==iMaxBound)

{

Page 30: cg report.docx

30

printf("INSIDE LOOP");

GeneratePoints();

n=0;

}

// printf("%d",ch);

ch--;

}while(ch>=0);

}

void mydisplay()

{

glClear(GL_COLOR_BUFFER_BIT);

callm();

glColor3f(2.0f,0.0f,2.0f);

glBegin(GL_POINTS);

printf("\nPOINTS");

Page 31: cg report.docx

31

glVertex3f(0.5,-0.7,-1.7);

// glVertex3f(50.0f,50.0f,50.0f);

glEnd();

glFlush();

}

/*void mydisplay(int button,int state,int x,int y)

{

if(button==GLUT_LEFT_BUTTON && state==GLUT_DOWN)

{

glClear(GL_COLOR_BUFFER_BIT);

// callm();

glColor3f(1.0f,1.0f,0.0f);

glBegin(GL_POINTS);

glVertex3f(0.5,0.5,0.5);

glVertex3f(50.0,50.0,50.0);

Page 32: cg report.docx

32

// printf("%f %f %f",fScreenX,fScreenY,fScreenZ);

glEnd();

glFlush();

}

}*/

void init()

{

glClearColor(0.0,0.0,0.0,0.0);

glColor3f(0.0,1.0,0.0);

//callm();

}

void reshape (int w, int h)

{

glViewport (0,0,(GLsizei)w,(GLsizei)h);

// glViewport(200,200,100,100);

Page 33: cg report.docx

33

glMatrixMode (GL_PROJECTION);

glLoadIdentity ();

glFrustum (-4.25, 4.25, -5.0, 5.0, 2.5, 25.0);

glMatrixMode (GL_MODELVIEW);

}

int main(int argc,char **argv)

{

glutInit(&argc,argv);

glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);

glutInitWindowSize(400,400);

glutInitWindowPosition(100,100);

glutCreateWindow("3d fractals");

init();

printf("3dFRACTALS");

glutDisplayFunc(mydisplay);

Page 34: cg report.docx

34

glutReshapeFunc(reshape);

glutMainLoop();

return 0;

}

Page 35: cg report.docx

35

BUILDING AND RUNNING PROJECTS:

Run the Project

Page 36: cg report.docx

36

CONCLUTION:

Thus Generation of volumetric escape time fractals has been

implemented General quadratic mappings, when extended to the third

dimension, produce a wide range of visually striking objects. From our

observations, the most visually interesting forms are relatively smooth and have

balanced (symmetrical) shapes.