/Users/lyon/j4p/src/bookExamples/ch26Graphics/PlotPoint2D.java
|
1 /**
2 * Created by IntelliJ IDEA.
3 * User: dlyon
4 * Date: Feb 2, 2004
5 * Time: 3:59:59 PM
6 * To change this template use Options | File Templates.
7 */
8 package bookExamples.ch26Graphics;
9
10 import java.awt.*;
11 import java.awt.geom.Point2D;
12
13 public class PlotPoint2D {
14 Fcn1 f = null;
15
16 PlotPoint2D(Fcn1 f) {
17 this.f = f;
18 }
19
20 public void plotLine(Point2D p1, Point2D p2, Graphics g) {
21 g.drawLine((int) p1.getX(),
22 (int) p1.getY(),
23 (int) p2.getX(),
24 (int) p2.getY());
25 }
26
27 public void paint(Graphics g) {
28 Point2D p1 = f.getPoint(0);
29 for (double t = 0; t <= 1.01; t = t + 0.01) {
30 Point2D p2 = f.getPoint(t);
31 plotLine(p1, p2, g);
32 p1 = p2;
33 }
34 }
35 }
36