DATE:29TH JULY 2013
TITLE:IMPLEMENTATION OF BRESNHAM LINE DRAWING ALGORITHM IN JAVA
*/
import java.applet.*;
import java.awt.*;
import java.util.*;
public class bresnham extends Applet
{
double x1,y1,x2,y2;
double dx,dy,steps,x,y,k;
Scanner sc=new Scanner(System.in);
double xc,yc;
public bresnham(){
System.out.println("ENTER X1 Y1");
x1=sc.nextDouble();
y1=sc.nextDouble();
System.out.println("ENTER X2 Y2");
x2=sc.nextDouble();
y2=sc.nextDouble();
}
public void paint(Graphics g)
{
int ch=6;
dx=Math.abs(x2-x1);
dy=Math.abs(y2-y1);
x=x1;
y=y1;
double e=(2*dy)-(dx);
int i=1;
//THIS PROGRAM IS CODED BY TG6483
one: for(int j=10;ch==6;j++)
{
g.fillOval((int)x,(int)y,5,5);
while(e>=0)
{
y=y+1;
e=e-(2*dx);
}
x=x+1;
e=e+(2*dy);
i++;
if(i<=dx)
ch=6;
else
break one;
}
}
}
/*<applet code="bresnham.class" width="1000" height="1000">
</applet>*/
/*
OUTPUT:
bash-3.00$ appletviewer bresnham.java
ENTER X1 Y1
500
200
ENTER X2 Y2
200
600
No comments:
Post a Comment