computer graphics cs 385 january 31, 2005. fractals some definitions object which is self-similar at...
TRANSCRIPT
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 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.
The Mandelbrot Set
A Julia Set
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
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
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.
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.
#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;
}
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();
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
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();
}
glBegin arguments
• GL_POINTS
• GL_LINES
• GL_LINE_STRIP
• GL_LINE_LOOP
• GL_TRIANGLES
• GL_TRIANGLE_STRIP
• GL_QUAD_STRIP
• GL_TRIANGLE_FAN
Next Monday
Text Color and an Introduction to Viewing