Lab 16

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 43

Bài 1:

Sources:
#include <cmath>
#include <vector>
#include <windows.h>
#include <gl/glut.h>

using namespace std;

#define eps 0.00001


#define WINDOW_WIDTH 500.0
#define WINDOW_HEIGHT 500.0
#define pi (2 * acos(0.0))
#define MAX_VAL 9999999
#define MIN_VAL -9999999

class Point {
public:
double x, y, z;

Point() {}

Point(double a, double b, double c) : x(a), y(b), z(c) {}

~Point() {}

double dot(Point v) {
return x * v.x + y * v.y + z * v.z;
}

Point operator+(Point pt) {


return Point(x + pt.x, y + pt.y, z + pt.z);
}

Point operator-(Point pt) {


return Point(x - pt.x, y - pt.y, z - pt.z);
}

Point operator*(double v) {
return Point(x * v, y * v, z * v);
}

Point operator*(Point v) {
return Point(y * v.z - z * v.y, z * v.x - x * v.z, x * v.y - y * v.x);
}

Point operator/(double pt) {


return Point(x / pt, y / pt, z / pt);
}

Point normalize() {
return *this / sqrt(x * x + y * y + z * z);
}
};
Point pos(0, 0, -150);
Point u(0, 1, 0);
Point r(1, 0, 0);
Point l(0, 0, 1);

// Biến toàn cục cho số lần lặp (iterations)


int iterations = 2;

// Hàm vẽ đường cong Koch với cấp độ khác nhau


void drawKoch(double x1, double y1, double x2, double y2, int it) {
float angle = 60 * (pi / 180);
double x3 = (2 * x1 + x2) / 3;
double y3 = (2 * y1 + y2) / 3;
double x4 = (x1 + 2 * x2) / 3;
double y4 = (y1 + 2 * y2) / 3;
double x = x3 + (x4 - x3) * cos(angle) + (y4 - y3) * sin(angle);
double y = y3 - (x4 - x3) * sin(angle) + (y4 - y3) * cos(angle);

if (it > 0) {
drawKoch(x1, y1, x3, y3, it - 1);
drawKoch(x3, y3, x, y, it - 1);
drawKoch(x, y, x4, y4, it - 1);
drawKoch(x4, y4, x2, y2, it - 1);
} else {
glBegin(GL_LINES); {
glVertex3f(x1, y1, 0);
glVertex3f(x3, y3, 0);
glVertex3f(x3, y3, 0);
glVertex3f(x, y, 0);
glVertex3f(x, y, 0);
glVertex3f(x4, y4, 0);
glVertex3f(x4, y4, 0);
glVertex3f(x2, y2, 0);
}
glEnd();
}
}

// Hàm hiển thị


void display() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(pos.x, pos.y, pos.z, pos.x + l.x, pos.y + l.y, pos.z + l.z, u.x, u.y,
u.z);
glMatrixMode(GL_MODELVIEW);

// Tô màu và vẽ đường cong Koch


glColor3f(1.0, 0, 0);
drawKoch(50, 0, 0, 100, iterations);
glColor3f(0, 1.0, 0);
drawKoch(0, 100, -50, 0, iterations);

glColor3f(0, 0, 1.0);
drawKoch(-50, 0, 50, 0, iterations);

glutSwapBuffers();
}

void init() {
glClearColor(0, 0, 0, 0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(80, 1, 1, 1000.0);
}

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


glutInit(&argc, argv);
glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT);
glutInitWindowPosition(0, 0);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGB);
glutCreateWindow("My OpenGL Program");

init();
glEnable(GL_DEPTH_TEST);
glutDisplayFunc(display);
glutMainLoop();
return 0;

Bài tập:
- Thay đổi các cấp hiển thị đường cong

- Thay đổi hình dạng ban đầu của đường cong

- Tô màu cho đường cong

1. Thay đổi số cấp hiển thị (iterations):


Thay đổi giá trị của biến iterations để điều chỉnh số lần lặp khi vẽ đường cong
Koch. Ví dụ, thay int iterations = 2; thành int iterations = 3; để tăng độ phức tạp.

2. Thay đổi hình dạng ban đầu:


Điều chỉnh các giá trị của hàm drawKoch trong hàm display.Ví dụ:
drawKoch(-100, 0, 100, 0, iterations); // Đoạn ngang
drawKoch(100, 0, 0, 150, iterations); // Đoạn chéo lên phải
drawKoch(0, 150, -100, 0, iterations); // Đoạn chéo xuống trái
3. Tô màu cho đường cong:
- Sử dụng glColor3f để thay đổi màu sắc. Mỗi đoạn đường cong có thể
được vẽ với màu khác nhau bằng cách gọi glColor3f trước khi gọi
drawKoch Tô màu cho đường cong:
- Sử dụng glColor3f để thay đổi màu sắc. Mỗi đoạn đường cong có thể
được vẽ với màu khác nhau bằng cách gọi glColor3f trước khi gọi
drawKoch.
Bài 2:

Sources:

#include <GL/glut.h>

#include <complex>

using std::complex;

// Render the Mandelbrot set into the image array.


// The parameters specify the region on the complex plane to plot.

void compute_mandelbrot( double left, double right, double top, double


bottom )

// The number of times to iterate before we assume that a point isn't in the

// Mandelbrot set.

// (You may need to turn this up if you zoom further into the set.)

const int MAX_ITERATIONS = 500;

const int width = glutGet( GLUT_WINDOW_WIDTH );

const int height = glutGet( GLUT_WINDOW_HEIGHT );

glBegin( GL_POINTS ); // start drawing in single pixel mode

for( int y = 0; y < height; ++y )


{

for( int x = 0; x < width; ++x )

// Work out the point in the complex plane that

// corresponds to this pixel in the output image.

complex<double> c( left + ( x * ( right - left ) / width ),

top + ( y * ( bottom - top ) / height ) );

// Start off z at (0, 0).

complex<double> z( 0.0, 0.0 );

// Iterate z = z^2 + c until z moves more than 2 units

// away from (0, 0), or we've iterated too many times.

int iterations = 0;
while( abs( z ) < 2.0 && iterations < MAX_ITERATIONS )

z = ( z * z ) + c;

++iterations;

if( iterations == MAX_ITERATIONS )

glColor3f( 1.0, 0.0, 0.0 ); // Set color to draw mandelbrot

// z didn't escape from the circle.

// This point is in the Mandelbrot set.

glVertex2i( x, y );

}
else

glColor3f( 0.0, 0.0, 0.0 ); //Set pixel to black

// z escaped within less than MAX_ITERATIONS

// iterations. This point isn't in the set.

glVertex2i( x, y );

glEnd();

}
void display()

glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );

glClear( GL_COLOR_BUFFER_BIT );

glMatrixMode( GL_PROJECTION );

glLoadIdentity();

const int width = glutGet( GLUT_WINDOW_WIDTH );

const int height = glutGet( GLUT_WINDOW_HEIGHT );

glOrtho( 0, width, 0, height, -1, 1 );

glMatrixMode( GL_MODELVIEW );

glLoadIdentity();

compute_mandelbrot( -2.0, 1.0, 1.125, -1.125 );


glutSwapBuffers();

int main( int argc, char** argv )

glutInit( &argc, argv );

glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGBA );

glutInitWindowSize( 300, 300 );

glutCreateWindow( "Mandelbrot" );

glutDisplayFunc( display );

glutMainLoop();

return 0;
}

Bài 3:
Sources:

#include <GL/glut.h>

#include <stdio.h>

/*

*defining a RGB struct to color the pixel

*/

struct Type_rgb{

float r;

float g;

float b;

};

/*

* pixel variable contain the value of the color pixel in


* the picture.

* pattern is a predefine set of color for a particular

* value.

*/

struct Type_rgb pixels[841*1440], pattern[999];

/*

* function mandelbrotset find where the number is in

* mandelbrotset or not and also assign a color to that

* coordinate with that iteration pattern.

*/

void mandelbrotset()

/*

* x0 :- is the real part of c value

* will range from -2.5 to 1.1.

* y0 :- is the imaginary part of c value

* will range from -1 to 1.1.

* x and y :- is the real and imaginary part of Zn.

* iteration :- is to keep control variable of the number

* of iteration

* max_iteration :- maximum number of iteration

* (which is one of bailout condition)

* loc :- represent the location pixel of the

* current x,y coordinate.


*/

float x0, y0, x, y, xtemp;

int iteration, max_iteration, loc=0;

printf("\nstart");

for(y0 = -1; y0 < 1.1; y0 = y0 + 0.0025)

for(x0 = -2.5; x0 < 1.1; x0 = x0 + 0.0025){

x = 0;

y = 0;

iteration = 0;

max_iteration = 1000;

/*

* (x*x) + (y*y) < (2*2) is the 2nd bailout condition ie

* the mandelbrot set is always within a radius of 2.

*/

while(((x*x) + (y*y) < (2*2)) && iteration < max_iteration){

xtemp = (x*x) - (y*y) + x0;

y = (2*x*y) + y0;

x = xtemp;

iteration = iteration + 1;

if(iteration >= 999){

/*

* setting color pixel to Mandelbrot set coordinate

*to black.
*/

pixels[loc].r = 0;

pixels[loc].g = 0;

pixels[loc].b = 0;

}else{

/*

* setting color pixel to the reset of the coordinate by the

* pattern of no of iteration before bailout.

*/

pixels[loc].r = pattern[iteration].r;

pixels[loc].g = pattern[iteration].g;

pixels[loc].b = pattern[iteration].b;

loc = loc + 1;

void Init( )

/*

* Basic Opengl initialization.

* 1440 = (-2.5 - 1.1)/0.0025

* here total x coordinate distance / no of division.

* 840 = (-1 - 1.1)/0.0025 +1

* here total y coordinate distance / no of division.


*/

glViewport(0, 0, 1440, 841);

glMatrixMode(GL_MODELVIEW);

glLoadIdentity( );

glMatrixMode(GL_PROJECTION);

glLoadIdentity( );

gluOrtho2D(0, 1440, 0, 841);

int i;

float r, g, b;

/*

* Initializing all the pixels to white.

*/

for(i = 0; i < 841*1440; i++){

pixels[i].r = 1;

pixels[i].g = 1;

pixels[i].b = 1;

i = 0;

/*

* Initializing all the pattern color till 9*9*9

*/

for(r = 0.1; r <= 0.9; r= r+0.1)

for(g = 0.1; g <= 0.9; g = g+0.1)

for(b = 0.1; b <= 0.9; b = b+0.1){


pattern[i].r = b;

pattern[i].g = r;

pattern[i].b = g;

i++;

/*

* Initializing the rest of the pattern as 9*9*9 is 729.

* and we need up to 999 pattern as the loop bailout

* condition is 1000.

*/

for( ; i <= 999; i++){

pattern[i].r = 1;

pattern[i].g = 1;

pattern[i].b = 1;

mandelbrotset();

void onDisplay()

/*

* Clearing the initial buffer

*/

glClearColor(1, 1, 1, 0);

glClear(GL_COLOR_BUFFER_BIT);
/*

* Draw the complete Mandelbrot set picture.

*/

glDrawPixels(1440, 841, GL_RGB, GL_FLOAT, pixels);

glutSwapBuffers();

int main(int argc, char** argv)

/*

* Here basic Opengl initialization.

*/

glutInit(&argc, argv);

glutInitWindowSize (1440, 841);

glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);

glutInitWindowPosition (100, 100);

glutCreateWindow ("Mandelbrotset by SKR");

Init ();

/*

* connecting the Display function

*/

glutDisplayFunc(onDisplay);

/*

* starting the activities

*/
glutMainLoop();

return 0;

Bài 4: Bài Tập

1) Viết chương trình nhập n để vẽ đường cong Kock bậc n.


Sources:

#include <cmath>
#include <vector>
#include <windows.h>
#include <gl/glut.h>
#include <iostream>

using namespace std;

#define eps 0.00001


#define WINDOW_WIDTH 500.0
#define WINDOW_HEIGHT 500.0
#define pi (2 * acos(0.0))
#define MAX_VAL 9999999
#define MIN_VAL -9999999
class Point {
public:
double x, y, z;

Point() {}

Point(double a, double b, double c) : x(a), y(b), z(c) {}

~Point() {}

double dot(Point v) {
return x * v.x + y * v.y + z * v.z;
}

Point operator+(Point pt) {


return Point(x + pt.x, y + pt.y, z + pt.z);
}

Point operator-(Point pt) {


return Point(x - pt.x, y - pt.y, z - pt.z);
}

Point operator*(double v) {
return Point(x * v, y * v, z * v);
}

Point operator*(Point v) {
return Point(y * v.z - z * v.y, z * v.x - x * v.z, x * v.y - y * v.x);
}

Point operator/(double pt) {


return Point(x / pt, y / pt, z / pt);
}

Point normalize() {
return *this / sqrt(x * x + y * y + z * z);
}
};

Point pos(0, 0, -150);


Point u(0, 1, 0);
Point r(1, 0, 0);
Point l(0, 0, 1);
// Bi?n toàn c?c cho s? l?n l?p (iterations)
int iterations = 3;

// Hàm v? đư?ng cong Koch v?i c?p đ? khác nhau


void drawKoch(double x1, double y1, double x2, double y2, int it) {
float angle = 60 * (pi / 180);
double x3 = (2 * x1 + x2) / 3;
double y3 = (2 * y1 + y2) / 3;
double x4 = (x1 + 2 * x2) / 3;
double y4 = (y1 + 2 * y2) / 3;
double x = x3 + (x4 - x3) * cos(angle) + (y4 - y3) * sin(angle);
double y = y3 - (x4 - x3) * sin(angle) + (y4 - y3) * cos(angle);

if (it > 0) {
drawKoch(x1, y1, x3, y3, it - 1);
drawKoch(x3, y3, x, y, it - 1);
drawKoch(x, y, x4, y4, it - 1);
drawKoch(x4, y4, x2, y2, it - 1);
} else {
glBegin(GL_LINES); {
glVertex3f(x1, y1, 0);
glVertex3f(x3, y3, 0);
glVertex3f(x3, y3, 0);
glVertex3f(x, y, 0);
glVertex3f(x, y, 0);
glVertex3f(x4, y4, 0);
glVertex3f(x4, y4, 0);
glVertex3f(x2, y2, 0);
}
glEnd();
}
}

// Hàm hi?n th?


void display() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(pos.x, pos.y, pos.z, pos.x + l.x, pos.y + l.y, pos.z + l.z, u.x,
u.y, u.z);
glMatrixMode(GL_MODELVIEW);
// Tô màu và v? đư?ng cong Koch v?i h?nh d?ng khác
glColor3f(1.0, 0, 0);
drawKoch(-100, 0, 100, 0, iterations);

glColor3f(0, 1.0, 0);


drawKoch(100, 0, 0, 150, iterations);

glColor3f(0, 0, 1.0);
drawKoch(0, 150, -100, 0, iterations);

glutSwapBuffers();
}

void init() {
glClearColor(0, 0, 0, 0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(80, 1, 1, 1000.0);
}

// Hàm nh?p giá tr? `iterations`


void inputIterations() {
cout << "Nhap gia tri bac n cua duong cong Koch: ";
cin >> iterations;
}

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


// Nh?p giá tr? `iterations` trư?c khi kh?i t?o GLUT
inputIterations();

glutInit(&argc, argv);
glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT);
glutInitWindowPosition(0, 0);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGB);
glutCreateWindow("My OpenGL Program");

init();
glEnable(GL_DEPTH_TEST);
glutDisplayFunc(display);
glutMainLoop();

return 0;
}
2) Viết chương trình nhập n và vẽ đường cong C cấp n.

3) Viết chương trình nhập n và vẽ đường cong Rồng cấp n.


4) Viết chương trình sinh tập Mandelbrot.

Source:

#include <GL/glut.h>

#include <stdio.h>

#define WINDOW_WIDTH 800

#define WINDOW_HEIGHT 800

#define MAX_ITER 1000

void display() {

glClear(GL_COLOR_BUFFER_BIT);

glBegin(GL_POINTS);

for (int x = 0; x < WINDOW_WIDTH; ++x) {

for (int y = 0; y < WINDOW_HEIGHT; ++y) {

double zx = 0.0, zy = 0.0;

double cx = (x - WINDOW_WIDTH / 2.0) * 4.0 / WINDOW_WIDTH;

double cy = (y - WINDOW_HEIGHT / 2.0) * 4.0 / WINDOW_HEIGHT;

int iter;

for (iter = 0; iter < MAX_ITER; ++iter) {

double zx2 = zx * zx;

double zy2 = zy * zy;

if (zx2 + zy2 > 4.0) break;


double new_zx = zx2 - zy2 + cx;

double new_zy = 2.0 * zx * zy + cy;

zx = new_zx;

zy = new_zy;

if (iter == MAX_ITER) {

glColor3f(0.0, 0.0, 0.0); // Đi?m thu?c t?p h?p Mandelbrot

} else {

float color = (float)iter / MAX_ITER;

glColor3f(color, color, color); // Đi?m không thu?c t?p h?p

glVertex2f(x, y);

glEnd();

glFlush();

void init() {

glClearColor(1.0, 1.0, 1.0, 1.0);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

gluOrtho2D(0, WINDOW_WIDTH, 0, WINDOW_HEIGHT);

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

glutInit(&argc, argv);

glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);

glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT);

glutCreateWindow("Mandelbrot Set");

init();

glutDisplayFunc(display);

glutMainLoop();

return 0;

}
5) Viết chương trình sinh đường Pythagoras.

Source:

#include <GL/glut.h>

#include <math.h>

#define WINDOW_WIDTH 800

#define WINDOW_HEIGHT 800


void drawSquare(float x, float y, float size, float angle) {

float x1 = x + size * cos(angle);

float y1 = y + size * sin(angle);

float x2 = x1 - size * sin(angle);

float y2 = y1 + size * cos(angle);

float x3 = x - size * sin(angle);

float y3 = y + size * cos(angle);

glBegin(GL_POLYGON);

glVertex2f(x, y);

glVertex2f(x1, y1);

glVertex2f(x2, y2);

glVertex2f(x3, y3);

glEnd();

void drawPythagorasTree(float x, float y, float size, float angle, int depth) {

if (depth == 0) return;

drawSquare(x, y, size, angle);

float x1 = x + size * cos(angle);

float y1 = y + size * sin(angle);


float x2 = x1 - size * sin(angle);

float y2 = y1 + size * cos(angle);

float newSize = size * sqrt(2) / 2;

drawPythagorasTree(x2, y2, newSize, angle + M_PI / 4, depth - 1);

drawPythagorasTree(x1, y1, newSize, angle - M_PI / 4, depth - 1);

void display() {

glClear(GL_COLOR_BUFFER_BIT);

glColor3f(0.0, 1.0, 0.0);

drawPythagorasTree(300, 100, 100, 0, 8);

glFlush();

void init() {

glClearColor(1.0, 1.0, 1.0, 1.0);

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

gluOrtho2D(0, WINDOW_WIDTH, 0, WINDOW_HEIGHT);

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

glutInit(&argc, argv);

glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);

glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT);

glutCreateWindow("Pythagoras Tree");

init();

glutDisplayFunc(display);

glutMainLoop();

return 0;

}
6) Viết chương trình sinh tập Julia.

Source:

#include <GL/glut.h>

#include <stdio.h>

#include <math.h>

#define WINDOW_WIDTH 800


#define WINDOW_HEIGHT 800

#define MAX_ITER 1000

double c_real = -0.7;

double c_imag = 0.27015;

void display() {

glClear(GL_COLOR_BUFFER_BIT);

glBegin(GL_POINTS);

for (int x = 0; x < WINDOW_WIDTH; ++x) {

for (int y = 0; y < WINDOW_HEIGHT; ++y) {

double real = (x - WINDOW_WIDTH / 2.0) * 4.0 / WINDOW_WIDTH;

double imag = (y - WINDOW_HEIGHT / 2.0) * 4.0 /


WINDOW_HEIGHT;

double z_real = real;

double z_imag = imag;

int iter;

for (iter = 0; iter < MAX_ITER; ++iter) {

double z_real2 = z_real * z_real - z_imag * z_imag;

double z_imag2 = 2.0 * z_real * z_imag;

z_real = z_real2 + c_real;


z_imag = z_imag2 + c_imag;

if (z_real * z_real + z_imag * z_imag > 4.0) break;

float color = (float)iter / MAX_ITER;

glColor3f(color, color, color);

glVertex2f(x, y);

glEnd();

glFlush();

void init() {

glClearColor(1.0, 1.0, 1.0, 1.0);

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

gluOrtho2D(0, WINDOW_WIDTH, 0, WINDOW_HEIGHT);

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

glutInit(&argc, argv);

glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT);

glutCreateWindow("Julia Set");

init();

glutDisplayFunc(display);

glutMainLoop();

return 0;

}
7) Viết chương trình vẽ các đường cong tô vùng: Phoenix, Hilbert, Sierpinxki.

Source:

#include <GL/glut.h>

#include <stdio.h>

#include <stdlib.h>

#include <math.h>

#define WINDOW_WIDTH 800

#define WINDOW_HEIGHT 800

void drawPhoenix(int x, int y, int size, int iter) {

if (iter <= 0) {

glBegin(GL_POINTS);

glVertex2f(x, y);

glEnd();

return;

int new_size = size / 2;

drawPhoenix(x - new_size, y, new_size, iter - 1);

drawPhoenix(x + new_size, y, new_size, iter - 1);

drawPhoenix(x, y + new_size, new_size, iter - 1);

drawPhoenix(x, y - new_size, new_size, iter - 1);

}
void drawHilbert(int x, int y, int size, int iter, int direction) {

if (iter <= 0) return;

int new_size = size / 2;

drawHilbert(x - direction * new_size, y - new_size, new_size, iter - 1, -


direction);

drawHilbert(x - new_size, y + direction * new_size, new_size, iter - 1,


direction);

drawHilbert(x + new_size, y + direction * new_size, new_size, iter - 1,


direction);

drawHilbert(x + direction * new_size, y - new_size, new_size, iter - 1, -


direction);

void drawSierpinski(int x, int y, int size, int iter) {

if (iter <= 0) {

glBegin(GL_POINTS);

glVertex2f(x, y);

glEnd();

return;

int new_size = size / 2;


drawSierpinski(x, y, new_size, iter - 1);

drawSierpinski(x - size, y, new_size, iter - 1);

drawSierpinski(x + size, y, new_size, iter - 1);

drawSierpinski(x, y - size, new_size, iter - 1);

drawSierpinski(x, y + size, new_size, iter - 1);

void display() {

glClear(GL_COLOR_BUFFER_BIT);

glColor3f(0.0, 0.0, 0.0); // Đ?t màu v? là đen

// V? đư?ng cong Phoenix

glPointSize(2.0);

drawPhoenix(WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2,
WINDOW_WIDTH / 4, 8);

// V? đư?ng cong Hilbert

glPointSize(1.0);

drawHilbert(WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2,
WINDOW_WIDTH / 4, 5, 1);

// V? đư?ng cong Sierpinski

glPointSize(1.0);
drawSierpinski(WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2,
WINDOW_WIDTH / 4, 8);

glFlush();

void init() {

glClearColor(1.0, 1.0, 1.0, 1.0); // Đ?t màu n?n là tr?ng

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

gluOrtho2D(0, WINDOW_WIDTH, 0, WINDOW_HEIGHT);

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

glutInit(&argc, argv);

glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);

glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT);

glutCreateWindow("Tong hop");

init();

glutDisplayFunc(display);

glutMainLoop();

return 0;

You might also like