-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDDA_Line.java
More file actions
42 lines (38 loc) · 1.01 KB
/
DDA_Line.java
File metadata and controls
42 lines (38 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import java.awt.*;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class DDA_Line extends JPanel {
@Override
public void paint(Graphics g){
double dx, dy, steps, x, y, k;
double xc, yc;
double x1=50, y1=300, x2=280, y2= 380;
dx = x2-x1;
dy = y2-y1;
if(Math.abs(dx) > Math.abs(dy)){
steps = Math.abs(dx);
}
else{
steps = Math.abs(dy);
}
xc = (dx/steps);
yc = (dy/steps);
x = x1;
y= y1;
g.fillOval(200,500, 2,2);
for(k = 1;k<=steps;k++){
x = x+xc;
y = y+yc;
g.fillOval((int)x,(int)y,2,2);
}
}
public static void main(String[] args){
DDA_Line d1 = new DDA_Line();
JFrame frame = new JFrame("Line");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(d1);
frame.setSize(500,500);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}