0% found this document useful (0 votes)
58 views

Academic Year 2018 - 2021 Department: Information & Technology

The document is a computer graphics lab assignment submitted by a student named Ratna Priya. It includes 5 programming problems to create graphics objects like random pixels, a rainbow, a moving car, concentric circles, and a hut. For each problem, the student provides the code to generate the graphic and describes the expected output.

Uploaded by

yashar khan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views

Academic Year 2018 - 2021 Department: Information & Technology

The document is a computer graphics lab assignment submitted by a student named Ratna Priya. It includes 5 programming problems to create graphics objects like random pixels, a rainbow, a moving car, concentric circles, and a hut. For each problem, the student provides the code to generate the graphic and describes the expected output.

Uploaded by

yashar khan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Academic Year 2018 -2021

Department: Information & Technology

Assignment
Of
Computer Graphics Lab

Full Name: Ratna Priya Roll No.: 18BCA025


Subject: Bachelor’s of computer application Semester: “6”
Date of Submission: 09/05/2021

Student Sign: Professor Sign:


1. Write a program to generated ‘Random Pixels’ on the screen at every
interval of 500ms.
Code: -
#include <conio.h>
#include <graphics.h>
#include <dos.h>
#include <stdlib.h>

int main()
{
int gd = DETECT, gm;
int i, x, y;
initgraph(&gd, &gm, "C:\\TC\\BGI");

while (!kbhit())
{
for(i=0; i<=500; i++)
{
x=rand()%getmaxx();
y=rand()%getmaxy();
putpixel(x,y,8);
}
delay(500);
cleardevice();
}

getch();
closegraph();
return 0;
}
Output: -
2. Write a program to create the ‘Rainbow’ in graphics window.
Code: -
#include<stdio.h>
#include<graphics.h>
#include<dos.h>
void rainbow()
{
int gdriver = DETECT,gmode;
int x, y, i;

initgraph(&gdriver,&gmode,"C:\\Turboc3\\BGI");

x = getmaxx() / 2;
y = getmaxy() / 2;

for (i=30; i<200; i++)


{

delay(100);
setcolor(i/10);

arc(x, y, 0, 180, i-10);


}
}
int main()
{
rainbow();
getch();
}
Output: -
3. Write a program to create a ‘Moving Car’ in graphics window.
Code: -
#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, "C:\\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, GREEN);

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;
}
Output: -
4. Write a program to create the ‘Concentric Circles’ in graphics window.
Code: -
#include<stdio.h>
#include<graphics.h>
#include<conio.h>

int main(){
int gd = DETECT,gm;
int x ,y;
initgraph(&gd, &gm, "C:\\TC\\BGI");

x = getmaxx()/2;
y = getmaxy()/2;

outtextxy(240, 50, "Concentric Circles");

setcolor(RED);
circle(x, y, 30);
setcolor(GREEN);
circle(x, y, 50);
setcolor(YELLOW);
circle(x, y, 70);
setcolor(BLUE);
circle(x, y, 90);

getch();
closegraph();
return 0;
}
Output: -
5. Write the program to create the ‘HUT’ in the graphics window.
#include<graphics.h>
#include<conio.h>
int main(){
int gd = DETECT,gm;
initgraph(&gd, &gm, "C:\\TC\\BGI");

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);

setfillstyle(SOLID_FILL, RED);
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;
}
Output: -

You might also like