0% found this document useful (0 votes)
102 views4 pages

Practical No 4 CG

The document describes code to display simple shapes like a star, car, and hut using graphics primitives in C++. The star code uses line commands to draw three lines forming a star shape. The car code uses multiple line and arc commands to draw a moving car on the screen. It fills areas with color and includes circles for wheels. The hut code uses rectangles and lines to outline a hut shape and fills interior areas with different patterns.

Uploaded by

Kartik Guleria
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
102 views4 pages

Practical No 4 CG

The document describes code to display simple shapes like a star, car, and hut using graphics primitives in C++. The star code uses line commands to draw three lines forming a star shape. The car code uses multiple line and arc commands to draw a moving car on the screen. It fills areas with color and includes circles for wheels. The hut code uses rectangles and lines to outline a hut shape and fills interior areas with different patterns.

Uploaded by

Kartik Guleria
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Practical No.

- 4

AIM: To display simple shapes (Like hut, star, car etc.) Using graphics
primitives

STAR:
#include<graphics.h>

#include<conio.h>

void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"C:\\TC\\bgi");
line(150,100,100,200);
line(100,200,200,200);
line(200,200,150,100);
line(100,125,200,125);
line(100,125,150,225);
line(150,225,200,125);

getch();
closegraph();
}

www.ahirlabs.com 1
CAR:
#include <stdio.h>
#include <graphics.h>
#include <conio.h>
#include <dos.h>

int main() {
int gd = DETECT, gm;
int i, maxx, midy;

initgraph(&gd, &gm, "X:\\TC\\BGI");


maxx = getmaxx();
midy = getmaxy()/2;

for (i=0; i < maxx-150; i=i+5) {


cleardevice();

setcolor(WHITE);
line(0, midy + 37, maxx, midy + 37);
setcolor(YELLOW);
setfillstyle(SOLID_FILL, RED);

line(i, midy + 23, i, midy);


line(i, midy, 40 + i, midy - 20);
line(40 + i, midy - 20, 80 + i, midy - 20);
line(80 + i, midy - 20, 100 + i, midy);
line(100 + i, midy, 120 + i, midy);
line(120 + i, midy, 120 + i, midy + 23);
line(0 + i, midy + 23, 18 + i, midy + 23);
arc(30 + i, midy + 23, 0, 180, 12);
line(42 + i, midy + 23, 78 + i, midy + 23);
arc(90 + i, midy + 23, 0, 180, 12);
line(102 + i, midy + 23, 120 + i, midy + 23);
line(28 + i, midy, 43 + i, midy - 15);
line(43 + i, midy - 15, 57 + i, midy - 15);
line(57 + i, midy - 15, 57 + i, midy);
line(57 + i, midy, 28 + i, midy);
line(62 + i, midy - 15, 77 + i, midy - 15);
line(77 + i, midy - 15, 92 + i, midy);
line(92 + i, midy, 62 + i, midy);
line(62 + i, midy, 62 + i, midy - 15);
floodfill(5 + i, midy + 22, YELLOW);
setcolor(BLUE);
setfillstyle(SOLID_FILL, DARKGRAY);
circle(30 + i, midy + 25, 9);
circle(90 + i, midy + 25, 9);
floodfill(30 + i, midy + 25, BLUE);
floodfill(90 + i, midy + 25, BLUE);
delay(100);
}

getch();
closegraph();
return 0;
}

Hut:
#include<graphics.h>
#include<conio.h>

int main(){
int gd = DETECT,gm;
initgraph(&gd, &gm, "X:\\TC\\BGI");
/* Draw Hut */
setcolor(WHITE);
rectangle(150,180,250,300);
rectangle(250,180,420,300);
rectangle(180,250,220,300);

line(200,100,150,180);
line(200,100,250,180);
line(200,100,370,100);
line(370,100,420,180);

/* Fill colours */
setfillstyle(SOLID_FILL, BROWN);
floodfill(152, 182, WHITE);
floodfill(252, 182, WHITE);
setfillstyle(SLASH_FILL, BLUE);
floodfill(182, 252, WHITE);
setfillstyle(HATCH_FILL, GREEN);
floodfill(200, 105, WHITE);
floodfill(210, 105, WHITE);

getch();
closegraph();
return 0;
}

You might also like