Draw Polygons in Graphics.h using drawpoly() & fillpoly() - Linux Mint - Libgraph - Graphics & Multimedia Lab - C++ Program

Draw Polygons in Graphics.h using drawpoly() & fillpoly() 
- Linux Mint - Libgraph - Graphics & Multimedia Lab - C++ Program


  • drawpoly( number_of_vertices+1  ,  sequence_of_polygonpoints ) - draw polygon
  • fillpoly( number_of_vertices+1  ,  sequence_of_polygonpoints ) - draw & fill polygon 
Source code:
#include<graphics.h>
using namespace std;

int main()
{
    int gd=DETECT, gm;
    int triangle[8]={20,150, 60,70, 110,150, 20,150};
    int rect[10]={150,60, 280,60, 280,150, 150,150, 150,60};
    int pentagon[12]={340,150, 320,110, 360,70, 400,110, 380,150, 340,150};
    int hexagon[14] ={ 360,260, 340,240, 360,220, 400,220, 420,240, 400,260, 360,260}; 
    int octagon[18]={450,150, 430,120, 430,100, 450,70, 500,70, 520,100, 520,120, 500,150, 450,150};
    int poly1[10]={50,400, 50,300, 150,400, 250,300, 250,400 };
    int poly2[12]={350,430, 350,390, 430,350, 350,310, 300,410, 350,430 };

    initgraph(&gd, &gm,NULL);
    
    outtextxy(150,15, "Polygon Drawing in Graphics.h using drawpoly() & fillpoly().");      
    
     
    drawpoly(4,triangle);  
    outtextxy(30,160, "Triangle");
        
    drawpoly(5,rect);  
    outtextxy(190, 160, "Rectangle");   
    drawpoly(6,pentagon);  
    outtextxy(330, 160, "Pentagon");
    drawpoly(9,octagon);
    outtextxy(450, 160, "Octagon");
    

    fillpoly(7,hexagon);
    outtextxy(362, 262, "Hexagon");     

    drawpoly(5,poly1);
    drawpoly(6,poly2);
    outtextxy(400, 400, "Polygon");
  
    getch();
    closegraph();
    return 0;
}
  

Output:

nn@linuxmint ~ $ g++ g4.cpp -lgraph
g4.cpp: In function ‘int main()’:
g4.cpp:18: warning: deprecated conversion from string constant to ‘char*’
g4.cpp:22: warning: deprecated conversion from string constant to ‘char*’
g4.cpp:25: warning: deprecated conversion from string constant to ‘char*’
g4.cpp:27: warning: deprecated conversion from string constant to ‘char*’
g4.cpp:29: warning: deprecated conversion from string constant to ‘char*’
g4.cpp:33: warning: deprecated conversion from string constant to ‘char*’
g4.cpp:37: warning: deprecated conversion from string constant to ‘char*’
nn@linuxmint ~ $ ./a.out
a.out: ../../src/xcb_io.c:249: process_responses: Assertion `(((long) (dpy->last_request_read) - (long) (dpy->request)) <= 0)' failed.
Aborted
nn@linuxmint ~ $ 


3 comments:

  1. I appreciate that you produced this wonderful article to help us get more knowledge about this topic.
    I know, it is not an easy task to write such a big article in one day, I've tried that and I've failed. But, here you are, trying the big task and finishing it off and getting good comments and ratings. That is one hell of a job done!

    Selenium training in bangalore
    Selenium training in Chennai
    Selenium training in Bangalore
    Selenium training in Pune
    Selenium Online training
    Selenium interview questions and answers


    ReplyDelete

Related Posts Plugin for WordPress, Blogger...