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.
trang9/21
Chuyển đổi dữ liệu24.11.2017
Kích3.11 Mb.
#34506
1   ...   5   6   7   8   9   10   11   12   ...   21
5.2.2.2 Vertical Lines

Vertical lines are drawn with the vline function:

void vline(BITMAP *bmp, int x, int y1, int y2, int color)

The VLines program (see Figure 3.11) is the same as the HLines program except

for a single function call inside the while loop. Also note that this program uses

a single X variable and two Y variables, y1 and y2. Here is the listing:

//display screen resolution

textprintf(screen, font, 0, 0, 15, "VLines Program - %dx%d - Press ESC to quit",

SCREEN W, SCREEN H);

//wait for keypress



while(!key[KEY ESC])

{

//set a random location

x = 10 + rand() % (SCREEN W-20);

y1 = 10 + rand() % (SCREEN H-20);

y2 = 10 + rand() % (SCREEN H-20);

//set a random color

red = rand() % 255;

green = rand() % 255;

blue = rand() % 255;

color = makecol(red,green,blue);

//draw the vertical line

vline(screen,x,y1,y2,color);

}

5.2.3 Rectangles

The next logical step is a twodimensional object containing points in both the X-axis and the Y-axis. Although a triangle would be the next best thing, I believe the rectangle is easier to deal with at this stage because triangles carry with them the connotation of the mighty polygon, and we aren’t quite there yet. Here is the rect function:

void rect(BITMAP *bmp, int x1, int y1, int x2, int y2, int color)

As you might have guessed, a rectangle is comprised strictly of two horizontal and two vertical lines; therefore, the rect function simply calls hline and vline to render its shape (see Figure 3.5).



//display screen resolution



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

//wait for keypress



while(!key[KEY ESC])

{

//set a random location

x1 = 10 + rand() % (SCREEN W-20);

y1 = 10 + rand() % (SCREEN H-20);

x2 = 10 + rand() % (SCREEN W-20);

y2 = 10 + rand() % (SCREEN H-20);

//set a random color

red = rand() % 255;

green = rand() % 255;

blue = rand() % 255;

color = makecol(red,green,blue);

//draw the rectangle

rect(screen,x1,y1,x2,y2,color);

}


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