CGR Output
CGR Output
CGR Output
h>
#include <graphics.h>
#include <math.h>
int main()
{
float x, y, x1, x2, y1, y2, dx, dy, length, i;
printf("Enter X1\n");
scanf("%f", &x1);
printf("Enter X2\n");
scanf("%f", &x2);
printf("Enter Y1\n");
scanf("%f", &y1);
printf("Enter Y2\n");
scanf("%f", &y2);
int gd = DETECT, gm;
initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");
dx = abs(x2 - x1);
dy = abs(y2 - y1);
if (dx >= dy)
{
length = dx;
}
else
{
length = dy;
}
dx = abs(x2 - x1) / length;
dy = abs(y2 - y1) / length;
x = x1 ;
y = y1 ;
i = 1;
while (i <= length)
{
putpixel(round(x), round(y), WHITE);
x = x + dx;
y = y + dy;
i = i + 1;
} getch();
closegraph();}
#include <stdio.h>
#include <graphics.h>
#include <math.h>
int main()
{
if (pi >= 0)
{
putpixel(round(x), round(y), WHITE);
y = y + 1;
pi = pi + 2 * dy - 2 * dx;
}
else if (pi < 0)
{
putpixel(round(x), round(y), WHITE);
pi = pi + 2 * dy;
}
x = x + 1;
} while (x <= x2);
getch();
closegraph();
}
#include <stdio.h>
#include <graphics.h>
#include <math.h>
int main()
{
int x1, x2, y1, y2, st_x, st_y, ep, i = 1, r, x, y;
float pi;
printf("Enter Radius");
scanf("%d", &r);
x = 0;
y = r;
pi = 3 - 2 * r;
int gd = DETECT, gm;
initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");
do
{
putpixel(200 + x, 200 + y, WHITE);
putpixel(200 + y, 200 + x, WHITE);
putpixel(200 - y, 200 + x, WHITE);
putpixel(200 - x, 200 + y, WHITE);
putpixel(200 - x, 200 - y, WHITE);
putpixel(200 - y, 200 - x, WHITE);
putpixel(200 + y, 200 - x, WHITE);
putpixel(200 + x, 200 - y, WHITE);
if (pi < 0)
{
x = x + 1;
pi = pi + (4 * x) + 6;
}
else if (pi >= 0)
{
x = x + 1;
y = y - 1;
pi = pi + 4 * (x - y) + 10;
}
} while (x < y);
getch();
closegraph();}
#include<stdio.h>
#include<graphics.h>
void flood(int,int,int,int);
int main(){
int gd = DETECT,gm;
int np = 7;
int h[] = {200, 100, 300, 50, 400, 100, 400, 200, 300, 250, 200, 200,
200, 100};
initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");
drawpoly(np,h);
flood(390,120,13,0);
getch();
closegraph();
}
void flood(int x,int y,int nc,int oc){
if(getpixel(x,y)==oc){
putpixel(x,y,nc);
flood(x + 1, y,nc,oc);
flood(x , y + 1 ,nc,oc);
flood(x - 1, y ,nc,oc);
flood(x , y - 1,nc,oc);
flood(x+1,y+1,nc,oc);
flood(x-1,y+1,nc,oc);
flood(x+1,y-1,nc,oc);
flood(x-1,y-1,nc,oc);
}
}
#include <stdio.h> // Triangle Flood Fill
#include <graphics.h>
void f_fill(int x, int y,int nc,int oc)
{
int c;
if (getpixel(x,y)==oc)
{
putpixel(x, y, nc);
f_fill(x + 1, y,nc,oc);
f_fill(x - 1, y,nc,oc);
f_fill(x, y + 1,nc,oc);
f_fill(x , y - 1,nc,oc);
}
}
int main()
{
int gm = DETECT, gd;
initgraph(&gm, &gd, "C:\\TURBOC3\\BGI");
int x1 = 300, y1 = 150;
int x2 = 375, y2 = 50;
int x3 = 450, y3 = 150;
}
}
int main()
{
int gm = DETECT, gd,x,y;
initgraph(&gm, &gd, "C:\\TURBOC3\\BGI");
// circle(x,y,r);
// b_fill(x, y, 13, 15);
line(320, 180, 370, 100);
line(370, 100, 420, 180);
line(420, 180, 380, 250);
line(380, 250, 350, 250);
line(350, 250, 320, 180);
x = (320+370+420+380+350)/5;
y = (180+100+180+250+250)/5;
b_fill(x, y, RED, 15);
getch();
closegraph();
return 0;
}
#include<stdio.h>
#include<graphics.h>
int fill(int x,int y,int fc ,int bc){
if(getpixel(x,y)!=fc&&getpixel(x,y)!=bc){
putpixel(x,y,fc);
fill(x+1,y,fc,bc);
fill(x-1,y,fc,bc);
fill(x,y+1,fc,bc);
fill(x,y-1,fc,bc);
}
}
int main(){
int gd=DETECT,gm;
initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");
int x1 = 100, y1 = 100;
int x2 = 300, y2 = 100;
int x3 = 250, y3 = 200;
int x4 = 150, y4 = 200;
int x = (x1+x2+x3+x4)/4;
int y = (y1+y2+y3+y4)/4;
fill (x, y, BLUE, 15);
getch();
closegraph();
}
#include <stdio.h>
#include <graphics.h>
int b_fill(int x, int y, int fc, int bc)
{
if (getpixel(x, y) != bc && getpixel(x, y) != fc)
{
putpixel(x, y, fc);
b_fill(x + 1, y, fc, bc);
b_fill(x, y + 1, fc, bc);
b_fill(x - 1, y, fc, bc);
b_fill(x, y - 1, fc, bc);
}
}
int main()
{
int gm = DETECT, gd,x,y;
initgraph(&gm, &gd, "C:\\TURBOC3\\BGI");
}
#include <stdio.h>
#include <graphics.h>
void f_fill(int x, int y,int nc,int oc)
{
int c;
if (getpixel(x,y)==oc)
{
putpixel(x, y, nc);
f_fill(x + 1, y,nc,oc);
f_fill(x - 1, y,nc,oc);
f_fill(x, y + 1,nc,oc);
f_fill(x , y - 1,nc,oc);
}
}
int main()
{
int gm = DETECT, gd;
initgraph(&gm, &gd, "C:\\TURBOC3\\BGI");
rectangle(100,100,400,200);
int x =150;
int y = 150 ;
f_fill(x, y, 14,0);
getch();
closegraph();
}
#include <stdio.h>
#include <graphics.h>
int main()
{int gm = DETECT, gd;
initgraph(&gm, &gd, "C:\\TURBOC3\\BGI");
int x1, y1, x2, y2,sx,sy;
printf("Enter Coordinates Of Line");
scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
line(x1,y1,x2,y2);
outtextxy(70 , 70,"Before Translation");
printf("Enter Translation Factor sx,sy");
scanf("%d %d",&sx,&sy);
x1 = sx + x1,y1 = sy + y1,x2 = sx + x2,y2 = sy + y2;
outtextxy(470 ,70,"After Translation");
line(x1,y1,x2,y2);
getch();
closegraph();
}
#include <stdio.h>
#include <graphics.h>
int main() {
int gm = DETECT, gd;
initgraph(&gm, &gd, "C:\\TURBOC3\\BGI");
int x1, y1, x2, y2, x3, y3, sx, sy;
getch();
closegraph();
return 0;
}
#include <stdio.h>
#include <graphics.h>
int main() {
int gm = DETECT, gd;
initgraph(&gm, &gd, "C:\\TURBOC3\\BGI");
int x1, y1, x2, y2, sx, sy;
getch();
closegraph();
return 0;
}
#include <stdio.h>
#include <graphics.h>
#include <math.h>
int main()
{ int gm = DETECT, gd;
initgraph(&gm, &gd, "C:\\TURBOC3\\BGI");
float x, y, x1, y1, x2, y2, x3, y3, x4, y4;
int r = 30;
double x1d, y1d, x2d, y2d, x3d, y3d, x4d, y4d;
x1 = 300, y1 = 150;
x2 = 375, y2 = 50;
x3 = 450, y3 = 150;
line(x1, y1, x2, y2);
line(x2, y2, x3, y3);
line(x3, y3, x1, y1);
double t = ((3.1428 * r )/180);
x1d = x1 * cos(t) - y1 * sin(t);
y1d = x1 * sin(t) + y1 * cos(t);
x2d = x2 * cos(t) - y2 * sin(t);
y2d = x2 * sin(t) + y2 * cos(t);
x3d = x3 * cos(t) - y3 * sin(t);
y3d = x3 * sin(t) + y3 * cos(t);
line((int)x1d, (int)y1d, (int)x2d, (int)y2d);
line((int)x2d, (int)y2d, (int)x3d, (int)y3d);
line((int)x3d, (int)y3d, (int)x1d, (int)y1d);
getch();
closegraph();
}
#include <stdio.h>
#include <graphics.h>
#include <math.h>
int main() {
int gm = DETECT, gd;
initgraph(&gm, &gd, "C:\\TURBOC3\\BGI");
getch();
closegraph();
return 0;
}