Computer Graphics CS 385 January 31, 2005. Fractals Some definitions Object which is self-similar at...

19
Computer Graphics CS 385 January 31, 2005

Transcript of Computer Graphics CS 385 January 31, 2005. Fractals Some definitions Object which is self-similar at...

Page 1: Computer Graphics CS 385 January 31, 2005. Fractals Some definitions Object which is self-similar at all scales. Regardless of scale the same level of.

Computer Graphics

CS 385

January 31, 2005

Page 2: Computer Graphics CS 385 January 31, 2005. Fractals Some definitions Object which is self-similar at all scales. Regardless of scale the same level of.

Fractals

Some definitions

• Object which is self-similar at all scales. Regardless of scale the same level of detail and appearance is present

• A System having similar detail at all scales, leading to intricate patterns and unexpected features. A system with a non-integer dimension.

• Computer-generated images corresponding to mathematical equations, that repeat self-similar patterns at infinitely receding levels of organization.

Page 3: Computer Graphics CS 385 January 31, 2005. Fractals Some definitions Object which is self-similar at all scales. Regardless of scale the same level of.

The Mandelbrot Set

Page 4: Computer Graphics CS 385 January 31, 2005. Fractals Some definitions Object which is self-similar at all scales. Regardless of scale the same level of.
Page 5: Computer Graphics CS 385 January 31, 2005. Fractals Some definitions Object which is self-similar at all scales. Regardless of scale the same level of.

A Julia Set

Page 6: Computer Graphics CS 385 January 31, 2005. Fractals Some definitions Object which is self-similar at all scales. Regardless of scale the same level of.
Page 7: Computer Graphics CS 385 January 31, 2005. Fractals Some definitions Object which is self-similar at all scales. Regardless of scale the same level of.
Page 8: Computer Graphics CS 385 January 31, 2005. Fractals Some definitions Object which is self-similar at all scales. Regardless of scale the same level of.
Page 9: Computer Graphics CS 385 January 31, 2005. Fractals Some definitions Object which is self-similar at all scales. Regardless of scale the same level of.
Page 10: Computer Graphics CS 385 January 31, 2005. Fractals Some definitions Object which is self-similar at all scales. Regardless of scale the same level of.

The Sierpinski Gasket

This object is defined recursively but its definition also has a random component.

Nevertheless, the process always converges to a geometric object that looks the same.

The theme here is: Order in Chaos

Page 11: Computer Graphics CS 385 January 31, 2005. Fractals Some definitions Object which is self-similar at all scales. Regardless of scale the same level of.

Non-Formal Description

1. Draw a triangle

2. Pick a point p in the triangle at random and draw it

3. Pick a vertex v of the triangle at random

4. Find the point q halfway between v and p

5. Go back to step 2 with q playing the role of p

Page 12: Computer Graphics CS 385 January 31, 2005. Fractals Some definitions Object which is self-similar at all scales. Regardless of scale the same level of.

Representing Points in OpenGL

In OpenGL, a point is often called a vertex

There is a family of functions that start out

glVertex and can be used for various data types in either 2 or 3 dimensions.

Page 13: Computer Graphics CS 385 January 31, 2005. Fractals Some definitions Object which is self-similar at all scales. Regardless of scale the same level of.

Representing Points in OpenGL

Examples of glVertex are glVertex2f and glVertex3i

If the datatype is represented by the letter v, then this indicates that the function takes a pointer to an array as its argument.

Page 14: Computer Graphics CS 385 January 31, 2005. Fractals Some definitions Object which is self-similar at all scales. Regardless of scale the same level of.

#include <GL/glut.h>

void init(void){

glClearColor(1.0,1.0,1.0,1.0);glColor3f(0.0,0.0,0.0);

}

void display(void){ glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_POINTS); glVertex2f(0,0); glEnd(); glFlush();}

int main(int argc, char** argv){

glutInit(&argc, argv);glutCreateWindow(“A Point”);glutDisplayFunc(display);init();glutMainLoop();return 0;

}

Page 15: Computer Graphics CS 385 January 31, 2005. Fractals Some definitions Object which is self-similar at all scales. Regardless of scale the same level of.

More Examples

glBegin(GL_POINTS);

glVertex2f(0,0);

glEnd();

glBegin(GL_LINES);

glVertex2f(0,0);

glVertex2f(1,1);

glEnd();

glBegin(GL_LINES); glVertex2f(1,1); glVertex2f(-1,-1); glVertex2f(-1,1); glVertex2f(1,-1);glEnd();

Page 16: Computer Graphics CS 385 January 31, 2005. Fractals Some definitions Object which is self-similar at all scales. Regardless of scale the same level of.

Back to the Sierpinski Gasket

Whenever the window needs to be redrawn, the OpenGL engine calls a function specified by the function

glutDisplayFunc

This function takes a function which take a void argument and returns a void. By convention, the function is often called display. Lets look at an implementation of a display function for the Sierpinski Gasket

Page 17: Computer Graphics CS 385 January 31, 2005. Fractals Some definitions Object which is self-similar at all scales. Regardless of scale the same level of.

typedef GLfloat point2[2];void display(void){

//Create an arbitrary trianglepoint2 vertices[3]={ {0.0, 0.0}, {250.0,500.0},{500.0,0.0}};

//Pick an arbitray point in the trianglestatic point2 p = {75.0, 50.0};

int j; for (int k=0; k<5000; k++)

{j=rand()%3; //pick a random vertex from 0,1 and 2//Compute the new pointp[0] = (p[0] + vertices[j][0])/2;p[1] = (p[1] + vertices[j][1])/2;

//Display the new pointglBegin(GL_POINTS); glVertex2fv(p);

glEnd();}glFlush();

}

Page 18: Computer Graphics CS 385 January 31, 2005. Fractals Some definitions Object which is self-similar at all scales. Regardless of scale the same level of.

glBegin arguments

• GL_POINTS

• GL_LINES

• GL_LINE_STRIP

• GL_LINE_LOOP

• GL_TRIANGLES

• GL_TRIANGLE_STRIP

• GL_QUAD_STRIP

• GL_TRIANGLE_FAN

Page 19: Computer Graphics CS 385 January 31, 2005. Fractals Some definitions Object which is self-similar at all scales. Regardless of scale the same level of.

Next Monday

Text Color and an Introduction to Viewing