Created
February 22, 2020 17:21
-
-
Save MinSomai/48dee69b50abb3c12436a8513df0735d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package hw; | |
import java.lang.Math; | |
import java.awt.Graphics; | |
import java.util.Scanner; | |
import java.applet.Applet; | |
public class DDA13 extends Applet { | |
int x1, x2, y1, y2; | |
double steps; | |
double dx, dy; | |
double xInc, yInc; | |
double x, y; | |
int xx, yy; | |
public void paint(Graphics g) { | |
Scanner input = new Scanner(System.in); | |
System.out.println("Enter x1,y1,x2 y2"); | |
x1 = input.nextInt(); | |
y1 = input.nextInt(); | |
; | |
x2 = input.nextInt(); | |
; | |
y2 = input.nextInt(); | |
; | |
dx = x2 - x1; | |
dy = y2 - y1; | |
if (Math.abs(dx) > Math.abs(dy)) { | |
steps = Math.abs(dx); | |
} else { | |
steps = Math.abs(dy); | |
} | |
xInc = dx / steps; | |
yInc = dy / steps; | |
x = x1; | |
y = y1; | |
System.out.println(steps); | |
for (int i = 0; i < steps; i++) { | |
x = x + Math.round(xInc); | |
y = y + Math.round(yInc); | |
xx = (int) x; | |
yy = (int) y; | |
System.out.println(x + " " + y); | |
g.fillOval(xx, yy, 10, 10); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment