แนวคิด
ตอนนี้ไฟล์ส่วนหัว graphics.h มีฟังก์ชัน fillpoly() ซึ่งใช้ในการวาดและเติมรูปหลายเหลี่ยม เช่น สามเหลี่ยม สี่เหลี่ยมผืนผ้า ห้าเหลี่ยม หกเหลี่ยม เป็นต้น ดังนั้นฟังก์ชันนี้จึงจำเป็นต้องมีอาร์กิวเมนต์เดียวกันกับ drawpoly()
ไวยากรณ์
void fillpoly( int number, int *polypoints );
ในกรณีนี้ ตัวเลขจะระบุ (n + 1) จำนวนจุด โดยที่ n คือจำนวนจุดยอดในรูปหลายเหลี่ยมและจุดหลายจุดจะชี้ไปที่ลำดับของจำนวนเต็ม (n*2)
ป้อนข้อมูล
arr[] = {320, 150, 400, 250, 250, 350, 320, 150};
ผลผลิต
คำอธิบาย
ดังนั้นการประกาศของ fillpoly() จึงมีสองอาร์กิวเมนต์:number ระบุ (n + 1) จำนวนจุดที่ n ถูกระบุเป็นจำนวนจุดยอดในรูปหลายเหลี่ยม อาร์กิวเมนต์ที่สอง เช่น polypoints ชี้ไปที่ลำดับของ (n * 2) จำนวนเต็ม ด้วยเหตุนี้ จำนวนเต็มแต่ละคู่จึงให้พิกัด x และ y ของจุดบนรูปหลายเหลี่ยม ดังนั้นเราจึงระบุ (n + 1) จุด เนื่องจากพิกัดจุดแรกควรเท่ากับ (n + 1)th สำหรับการวาดรูปที่สมบูรณ์
ตัวอย่าง
// C Implementation for fillpoly() #include <graphics.h> // driver code intmain(){ // Here gm1 is Graphics mode which is a computer display mode that // produces image using pixels. DETECT is a macro defined in // "graphics.h" header file intgd1 = DETECT, gm1; // Different coordinates for polygon intarr1[] = {320, 150, 400, 250, 250, 350, 320, 150}; // Here initgraph initializes the // graphics system by loading a // graphics driver from disk initgraph(&gd1, &gm1, ""); // fillpoly function fillpoly(4, arr1); getch(); // Here closegraph function closes the // graphics mode and deallocates // all memory allocated by // graphics system . closegraph(); return0; }
ผลลัพธ์