//Line drawing using DDA PROGRM
import java.util.Scanner;
import javax.swing.JFrame;
import java.awt.*;
class Ddr extends JFrame{
int x1,y1,x2,y2;
Ddr(double x1,double y1,double x2,double y2)
{ //constructor for Test class
this.x1=(int)x1;
this.y1=(int)y1;
this.x2=(int)x2;
this.y2=(int)y2;
setTitle("DDR"); // jframe title
setSize(1000,1000); // jframe size
setVisible(true); //set visibility
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public void paint(Graphics g)
{
g.setColor(Color.RED);
g.drawLine(x1,y1,x2,y2);
}
public static void main(String [] args)
{
Scanner rs=new Scanner(System.in);
System.out.println("Enter the point x1,y1,x2,and y2");
double X1=rs.nextInt();
double Y1=rs.nextInt();
double X2=rs.nextInt();
double Y2=rs.nextInt();
double nextX1, nextX2, nextY1, nextY2;
double slope=(Math.abs(Y2-Y1)/Math.abs(X2-X1));
System.out.println("Slope of the line is " slope);
if(slope<1 1="" be="" else="" ext="" if="" nextx1="" nexty1="" point="" slope="" system.out.println="" will="">1)
{
nextX1=X1 1/slope;
nextY1=Y1 1;
System.out.println("Next point will be " nextX1 " , " nextY1);
}
else
{
nextX1=X1 1;
nextY1=Y1 1;
System.out.println("Next point will be " nextX1 " , " nextY1);
}
Ddr t=new Ddr(X1,Y1,nextX1, nextY1);
}
}
1>
No comments:
Post a Comment
Please do not enter any spam link in the comment Box