Chủ nhiệm Bộ môn Ngô Hữu Phúc ĐỀ CƯƠng chi tiết bài giảNG



tải về 3.11 Mb.
trang11/21
Chuyển đổi dữ liệu24.11.2017
Kích3.11 Mb.
#34506
1   ...   7   8   9   10   11   12   13   14   ...   21
5.2.4.1 Filled Circles

The hollow circle function is interesting, but really seeing the full effect of circles requires the circlefill function:

void circlefill(BITMAP *bmp, int x, int y, int radius, int color)

The following program (shown in Figure 3.17) demonstrates the solid-filled

circle function.

122 Chapter 3 n 2D Vector Graphics Programming

//display screen resolution

textprintf ex(screen, font, 0, 0, 15, -1,"CircleFill Program - %dx%d - Press ESC to quit",SCREEN W, SCREEN H);

//wait for keypress



while(!key[KEY ESC])

{

//set a random location

x = 30 + rand() % (SCREEN W-60);

y = 30 + rand() % (SCREEN H-60);

radius = rand() % 30;

//set a random color

red = rand() % 255;

green = rand() % 255;

blue = rand() % 255;

color = makecol(red,green,blue);

//draw the filled circle

circlefill(screen, x, y, radius, color);

rest(25);

}

Figure 3.7

The CircleFill program draws filled circles.

Ellipses


The ellipse function is similar to the circle function, although the radius is

divided into two parameters—one for the horizontal and another for the vertical—as indicated:



void ellipse(BITMAP *bmp, int x, int y, int rx, int ry, int color)

The Ellipses program draws random ellipses on the screen using two parameters—radiusx and radiusy.



#include

#include "allegro.h"

int main(void)

{

int x,y,radiusx,radiusy;

int red,green,blue,color;

//initialize everything

allegro init();

install keyboard();

install timer();

srand(time(NULL));

//initialize video mode to 640x480

int ret = set gfx mode(GFX AUTODETECT WINDOWED, 640, 480, 0, 0);

if (ret != 0) {

allegro message(allegro error);

return 1;

}

//display screen resolution

textprintf ex(screen, font, 0, 0, 15, -1,

"Ellipses Program - %dx%d - Press ESC to quit",

SCREEN W, SCREEN H);

//wait for keypress

while(!key[KEY ESC])

{

//set a random location

x = 30 + rand() % (SCREEN W-60);

y = 30 + rand() % (SCREEN H-60);

radiusx = rand() % 30;

radiusy = rand() % 30;

//set a random color

red = rand() % 255;

green = rand() % 255;

blue = rand() % 255;

color = makecol(red,green,blue);

//draw the ellipse

ellipse(screen, x, y, radiusx, radiusy, color);

rest(25);

}

//end program

allegro exit();

return 0;

}

END OF MAIN()

Filled Ellipses

You can draw filled ellipses using the ellipsefill function, which takes the same

parameters as the ellipse function but simply renders each ellipse with a solid

filled color:

void ellipsefill(BITMAP *bmp, int x, int y, int rx, int ry, int color)

Figure 3.18 shows the output from the EllipseFill program.

//display screen resolution

textprintf ex(screen, font, 0, 0, 15, -1,"EllipseFill Program - %dx%d - Press ESC to quit",SCREEN W, SCREEN H);

//wait for keypress

while(!key[KEY ESC])

{

//set a random location

x = 30 + rand() % (SCREEN W-60);

y = 30 + rand() % (SCREEN H-60);

radiusx = rand() % 30;

radiusy = rand() % 30;

//set a random color

red = rand() % 255;

green = rand() % 255;

blue = rand() % 255;

color = makecol(red,green,blue);

//draw the filled ellipse

ellipsefill(screen, x, y, radiusx, radiusy, color);

rest(25);

}

- Yêu cầu SV chuẩn bị:

Đọc chương 3 tài liệu [1].

Đọc c ác phần tương ứng trong tài liệu [5].

Chú ý nghe giảng.

Tích cực tham gia phát biểu ý kiến



Каталог: files -> FileMonHoc
FileMonHoc -> NGÂn hàng câu hỏi lập trình cơ BẢn nhóm câu hỏI 2 ĐIỂM
FileMonHoc -> CHƯƠng 2 giới thiệu về LÝ thuyết số
FileMonHoc -> CÁc hệ MẬt khoá CÔng khai kháC
FileMonHoc -> BỘ MÔn duyệt chủ nhiệm Bộ môn
FileMonHoc -> Khoa công nghệ thông tin cộng hòa xã HỘi chủ nghĩa việt nam
FileMonHoc -> Chủ nhiệm Bộ môn Ngô Thành Long ĐỀ CƯƠng chi tiết bài giảNG
FileMonHoc -> Chủ nhiệm Bộ môn Phan Nguyên Hải ĐỀ CƯƠng chi tiết bài giảNG
FileMonHoc -> Khoa: CÔng nghệ thông tin cộng hòa xã HỘi chủ nghĩa việt nam
FileMonHoc -> MẬt mã khóA ĐỐi xứng lý thuyết cơ bản của Shannon
FileMonHoc -> Khoa công nghệ thông tin bài giảng LẬp trình cơ BẢn biên soạn

tải về 3.11 Mb.

Chia sẻ với bạn bè của bạn:
1   ...   7   8   9   10   11   12   13   14   ...   21




Cơ sở dữ liệu được bảo vệ bởi bản quyền ©hocday.com 2024
được sử dụng cho việc quản lý

    Quê hương