Programs of CG
Programs of CG
Programs of CG
#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();
}
#include <graphics.h>
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
setcolor(RED);
circle(100, 100, 50);
getch();
closegraph();
return 0;
}
#include<graphics.h>
#include<conio.h>
#include<stdio.h>
void main()
{
intgd = DETECT ,gm, i;
float x, y,dx,dy,steps;
int x0, x1, y0, y1;
initgraph(&gd, &gm, "C:\\TC\\BGI");
setbkcolor(WHITE);
x0 = 100 , y0 = 200, x1 = 500, y1 = 300;
dx = (float)(x1 - x0);
dy = (float)(y1 - y0);
if(dx>=dy)
{
steps = dx;
}
else
{
steps = dy;
}
dx = dx/steps;
dy = dy/steps;
x = x0;
y = y0;
i = 1;
while(i<= steps)
{
putpixel(x, y, RED);
x += dx;
y += dy;
i=i+1;
}
getch();
closegraph();
}
#include<stdio.h>
#include<graphics.h>
void drawline(int x0, int y0, int x1, int y1)
{
int dx, dy, p, x, y;
dx=x1-x0;
dy=y1-y0;
x=x0;
y=y0;
p=2*dy-dx;
while(x<x1)
{
if(p>=0)
{
putpixel(x,y,7);
y=y+1;
p=p+2*dy-2*dx;
}
else
{
putpixel(x,y,7);
p=p+2*dy;}
x=x+1;
}
}
int main()
{
int gdriver=DETECT, gmode, error, x0, y0, x1, y1;
initgraph(&gdriver, &gmode, "c:\\turboc3\\bgi");
printf("Enter co-ordinates of first point: ");
scanf("%d%d", &x0, &y0);
printf("Enter co-ordinates of second point: ");
scanf("%d%d", &x1, &y1);
drawline(x0, y0, x1, y1);
return 0;
}
9. Program to make screen saver in that display different size circles filled with
different colors and at random places.
#include<stdio.h>
#include<conio.h>
#include"graphics.h"
#include"stdlib.h"
void main()
{
intgd=DETECT,gm,i=0,x,xx,y,yy,r;
//Initializes the graphics system
initgraph(&gd,&gm,"c:\\tc\\bgi");
x=getmaxx();
y=getmaxy();
while(!kbhit())
{
i++;
setfillstyle(random(i),random(30));
circle(xx=random(x),yy=random(y),random(30));
setfillstyle(random(i),random(30));
floodfill(xx,yy,getmaxcolor());
delay(200);
}
getch();
}
#include <stdio.h>
#include <conio.h>
#include <graphics.h>
#include <dos.h>
int main()
{
int gd = DETECT, gm;
int i, x, y, flag=0;
initgraph(&gd, &gm, "C:\\TC\\BGI");
x = getmaxx()/2;
y = 30;
while (!kbhit())
{
if(y >= getmaxy()-30 || y <= 30)
flag = !flag;
setcolor(RED);
setfillstyle(SOLID_FILL, RED);
circle(x, y, 30);
floodfill(x, y, RED);
delay(50);
cleardevice();
if(flag)
{
y = y + 5;
}
else
{
y = y - 5;
}
}
getch();
closegraph();
return 0;
}