0% found this document useful (0 votes)
2K views

Write A Program To Draw Basic Graphics Construction Like Line

The document describes 3 programs to draw basic graphics in C++ using graphics libraries: 1. The first program draws basic shapes like lines, rectangles, arcs, circles, and ellipses. 2. The second program animates increasing colored circles with different fill patterns. 3. The third program animates a moving colored car made of lines, circles, and rectangles with fill colors.

Uploaded by

Nitasha sharma
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views

Write A Program To Draw Basic Graphics Construction Like Line

The document describes 3 programs to draw basic graphics in C++ using graphics libraries: 1. The first program draws basic shapes like lines, rectangles, arcs, circles, and ellipses. 2. The second program animates increasing colored circles with different fill patterns. 3. The third program animates a moving colored car made of lines, circles, and rectangles with fill colors.

Uploaded by

Nitasha sharma
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Write a Program to draw basic

graphics construction like line, circle,


arc, ellipse and rectangle.

#include<graphics.h>  
#include<conio.h>  
void main()  
{  
    intgd=DETECT,gm;  
    initgraph (&gd,&gm,"c:\\tc\\bgi");  
    setbkcolor(GREEN);  
    printf("\t\t\t\n\nLINE");  
    line(50,40,190,40);  
    printf("\t\t\n\n\n\nRECTANGLE");  
    rectangle(125,115,215,165);  
    printf("\t\t\t\n\n\n\n\n\n\nARC");  
    arc(120,200,180,0,30);  
    printf("\t\n\n\n\nCIRCLE");  
    circle(120,270,30);  
    printf("\t\n\n\n\nECLIPSE");  
    ellipse(120,350,0,360,30,20);  
    getch();  
}  

Output
Write a Program to draw
animation using increasing
circles filled with different colors
and patterns.
#include<graphics.h>  
#include<conio.h>  
void main()  
{  
    intgd=DETECT, gm, i, x, y;  
    initgraph(&gd, &gm, "C:\\TC\\BGI")  
    x=getmaxx()/3;  
    y=getmaxx()/3;  
    setbkcolor(WHITE);  
    setcolor(BLUE);  
    for(i=1;i<=8;i++)  
          {  
        setfillstyle(i,i);  
        delay(20);  
        circle(x, y, i*20);  
        floodfill(x-2+i*20,y,BLUE);  
    }  
    getch();  
    closegraph();  
}  
Output
Write a Program to make a
moving colored car using inbuilt
functions.
#include<graphics.h>  
#include<conio.h>  
int main()  
{  
    intgd=DETECT,gm, i, maxx, cy;  
    initgraph(&gd, &gm, "C:\\TC\\BGI");  
    setbkcolor(WHITE);  
    setcolor(RED);  
    maxx = getmaxx();  
    cy = getmaxy()/2;  
    for(i=0;i<maxx-140;i++)  
        {  
        cleardevice();  
        line(0+i,cy-20, 0+i, cy+15);  
        line(0+i, cy-20, 25+i, cy-20);  
        line(25+i, cy-20, 40+i, cy-70);  
        line(40+i, cy-70, 100+i, cy-70);  
        line(100+i, cy-70, 115+i, cy-20);  
        line(115+i, cy-20, 140+i, cy-20);  
        line(0+i, cy+15, 18+i, cy+15);  
        circle(28+i, cy+15, 10);  
        line(38+i, cy+15, 102+i, cy+15);  
        circle(112+i, cy+15,10);  
        line(122+i, cy+15 ,140+i,cy+15);  
        line(140+i, cy+15, 140+i, cy-20);  
     rectangle(50+i, cy-62, 90+i, cy-30);  
       setfillstyle(1,BLUE);  
       floodfill(5+i, cy-15, RED);  
       setfillstyle(1, LIGHTBLUE);  
        floodfill(52+i, cy-60, RED);  
        delay(10);  
         }  
    getch();  
    closegraph();  
    return 0;  
}  
Output

You might also like