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


Drawing Circles and Ellipses



tải về 3.11 Mb.
trang10/21
Chuyển đổi dữ liệu24.11.2017
Kích3.11 Mb.
#34506
1   ...   6   7   8   9   10   11   12   13   ...   21
5.2.4 Drawing Circles and Ellipses

Allegro also provides functions for drawing circles and ellipses, as you will see.

The circle-drawing function is called circle, surprisingly enough. This function

takes a set of parameters very similar to those you have seen already—the destination bitmap, x, y, the radius, and the color.

Circles

The circle function has this declaration:



120 Chapter 3 n 2D Vector Graphics Programming

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

To demonstrate, the Circles program draws random circles on the screen, as

shown in Figure 3.6.



#include

#include

int main(void)

{

int x,y,radius;

int red,green,blue,color;

//initialize some stuff

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) {

Figure 3.6

The Circles program draws random circles on the screen.

allegro message(allegro error);



return 1;

}

//display screen resolution

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

"Circles 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 circle

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

rest(25);

}

//end program

allegro exit();

return 0;

}

END OF MAIN()


Каталог: 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   ...   6   7   8   9   10   11   12   13   ...   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