DDA_algo
an anonymous user
·
import java.awt.*; import java.applet.*; import java.lang.*; public class DDA_algo extends Applet { int dx,dy,steps,x1,y1,x2,y2,x,y; float xinc,yinc; public void init() { this.setSize(1500,900); x1=50; y1=50; x2=250; y2=250; dx=(x2-x1); dy=(y2-y1); } public void paint(Graphics g) { if(dx>dy) { steps=Math.abs(dx); } else { steps=Math.abs(dy); } xinc=dx/steps; yinc=dy/steps; x=x1; y=y1; g.setColor(Color.CYAN); g.fillOval(x,y,5,5); try { for(int i=1;i<=steps;i++) { x=(int)(x+xinc); y=(int)(y+yinc); Thread.sleep(20); g.fillOval(x,y,5,5); } } catch(Exception e) { } } }
Output
(Run the program to view its output)
Comments