Anuditcg Lab
Anuditcg Lab
#include <graphics.h>
#include <conio.h>
//#include <math.h>
int main()
dx = x2 - x1;
dy = y2 - y1;
steps = abs(dx);
else
steps = abs(dy);
xinc = dx / steps;
yinc = dy / steps;
x = x1;
y = y1;
putpixel(x, y, WHITE);
x = x + xinc;
y = y + yinc;
getch();
closegraph();
return 0;
2) Setfills
#include <graphics.h>
#include <conio.h>
main()
setfillstyle(2, RED);
getch();
closegraph();
3) Boundary Fill
#include <stdio.h>
#include <conio.h>
#include <graphics.h>
putpixel(x, y, fill_color);
int main()
scanf("%d", &b_color);
scanf("%d", &f_color);
getch();
closegraph();
return 0;
4) Brehsenham
#include <stdio.h>
#include <graphics.h>
#include <conio.h>
//#include <math.h>
dx = abs(x2 - x1);
dy = abs(y2 - y1);
x = x1;
y = y1;
putpixel(x, y, 15);
getch();
closegraph();
}
int main() {
int x1, y1, x2, y2;
return 0;
}
5) DDA
#include <stdio.h>
#include <graphics.h>
#include <conio.h>
//#include <math.h>
main()
{
int x1, y1, x2, y2, dx, dy, steps, gd = DETECT, gm;
float xinc, yinc;
initgraph(&gd, &gm, (char*)"");
printf("Enter two line endpoints(x1,y1) and (x2,y2): ");
scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
dx = x2 - x1;
dy = y2 - y1;
if (abs(dx) > abs(dy))
{
steps = abs(dx);
}
else
{
steps = abs(dy);
}
xinc = dx / steps;
yinc = dy / steps;
putpixel(x1, y1, 15);
6) Line Graph
#include <graphics.h>
#include <conio.h>
main()
setlinestyle(SOLID_LINE, 0, THICK_WIDTH);
setlinestyle(DOTTED_LINE, 0, 1);
setlinestyle(DASHED_LINE, 0, 1);
// userbit line
getch();
closegraph();
7) MidPoint Ellipse
#include <stdio.h>
#include <conio.h>
#include <graphics.h>
main()
float p;
initgraph(&gd, &gm, (char *)"");
x = 0;
y = ry;
p = ry * ry - rx * rx * ry + 1 / 4 * rx * rx;
while (2 * ry * ry * x < 2 * rx * rx * y)
if (p < 0)
x += 1;
p = p + 2 * ry * ry * x + ry * ry;
else
x += 1;
y -= 1;
p = p + 2 * ry * ry * x - 2 * rx * rx * y + ry * ry;
}
while (y >= 0)
if (p > 0)
y -= 1;
p = p - 2 * rx * rx * y + rx * rx;
else
x += 1;
y -= 1;
p = p + 2 * ry * ry * x - 2 * rx * rx * y + rx * rx;
getch();
closegraph();
8) MidPoint
#include <stdio.h>
#include <graphics.h>
#include <conio.h>
main()
{
int r, xc, yc, x, y;
float p;
int gd = DETECT, gm;
initgraph(&gd, &gm, (char *)"");
p = 5 / 4 - r;
while (y >= x)
{
if (p < 0)
{
x += 1;
p = p + 2 * x + 1;
}
else
{
x += 1;
y -= 1;
p = p + 2 * x + 1 - 2 * y;
}
getch();
closegraph();
}
10) Circle
#include <graphics.h>
#include <conio.h>
main()
{
int gd = DETECT, gm;
initgraph(&gd, &gm, (char *)"");
getch();
closegraph();
}
11) Triangle
#include <graphics.h>
#include <conio.h>
main()
{
int gd = DETECT, gm;
initgraph(&gd, &gm, (char *)"");
// setcolor(CYAN);
line(350, 250, 100, 235);
line(100, 235, 70, 90);
line(70, 90, 350, 250);