Academic Year 2018 - 2021 Department: Information & Technology
Academic Year 2018 - 2021 Department: Information & Technology
Assignment
Of
Computer Graphics Lab
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;
delay(100);
setcolor(i/10);
int main() {
int gd = DETECT, gm;
int i, maxx, midy;
maxx = getmaxx();
midy = getmaxy()/2;
cleardevice();
setcolor(WHITE);
line(0, midy + 37, maxx, midy + 37);
setcolor(YELLOW);
setfillstyle(SOLID_FILL, GREEN);
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;
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: -