Algoritma Bresenham: Source Code
Algoritma Bresenham: Source Code
Algoritma Bresenham: Source Code
Source Code
#include
#include
#include
#include
<graphics.h>
<stdio.h>
<conio.h>
<math.h>
void main()
{
int gd = DETECT, gm = DETECT, s, dx, dy, m, x1, y1, x2, y2;
float xi, yi, x, y;
printf("Masukkan x1 = ");scanf("%d", &x1);
printf("Masukkan y1 = ");scanf("%d", &y1);
printf("Masukkan x2 = ");scanf("%d", &x2);
printf("Masukkan y2 = ");scanf("%d", &y2);
initgraph(&gd, &gm, "c:\\tc\\bgi");
cleardevice();
dx = x2 - x1;
dy = y2 - y1;
if (abs(dx) > abs(dy))
s = abs(dx);
else
s = abs(dy);
xi = dx / (float) s;
yi = dy / (float) s;
x = x1;
y = y1;
putpixel(x1, y1, 4);
for (m = 0; m < s; m++) {
x += xi;
y += yi;
putpixel(x, y, 4);
}
getch();
}
Implementasi
Implementasi dilakukan atau di compile di Turbo C++/C 4.0 dengan
menggunakan OS Windows 10.
Input :
Output :
Diperbesar (Output)