#include<stdio.h>di buat dengan nano dan di compile/test dengan gcc di linux ubuntu 9.10
#include<graphics.h>
void ikan(int,int,int,int);
void setPixel(int,int);
void main()
{
int x1,y1,x2,y2;
int gd=DETECT,gm=0;
initgraph(&gd,&gm,0);
printf(“Masukkan koordinat titik x1 : \n “);
scanf(“%d”,&x1);
printf(“Masukkan koordinat titik y1: \n “);
scanf(“%d”,&y1);
printf(“Masukkan koordinat titik x2: \n”);
scanf(“%d”,&x2);
printf(“Masukkan koordinat titik y2: \n “);
scanf(“%d”,&y2);
initgraph(&gd,&gm,0);
ikan(x1,y1,x2,y2);
getch();
closegraph();
}
void ikan(int x1,int y1,int x2,int y2)
{
int x,y;
int dx, dy;
int d;
dy=y2-y1;
dx=x2-x1;
d = dx – 2 * dy;
y = y1;
for (x = x1; x <= x2; x++)
{
putpixel(x,y,4);
if (d < 0)
{
y = y +1;
d = d + 2*dx – 2*dy;
}
else
{
d = d – 2*dy;
}
}
}
void setPixel(int x,int y)
{
putpixel(x,y,4);
}
Tuesday, November 9, 2010
Algoritma Bresenham dalam Bahasa C
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment