MCPcopy Create free account
hub / github.com/OpenSourcePhysics/osp / Circle

Class Circle

src/org/opensourcephysics/display/Circle.java:19–146  ·  view source on GitHub ↗

A Drawable circle that uses awt drawing. @author Wolfgang Christian @version 1.0

Source from the content-addressed store, hash-verified

17 * @version 1.0
18 */
19public class Circle implements Drawable {
20 public Color color = Color.red; // the drawing color
21 public int pixRadius = 6;
22 protected double x = 0;
23 protected double y = 0;
24
25 /**
26 * Constructs a fixed radius circle at the origin.
27 */
28 public Circle() {
29 this(0, 0);
30 }
31
32 /**
33 * Constructs a fixed radius circle at the given coordinates.
34 *
35 * The default radius is 6 pixels.
36 *
37 * @param _x
38 * @param _y
39 */
40 public Circle(double _x, double _y) {
41 x = _x;
42 y = _y;
43 }
44
45 /**
46 * Constructs a fixed radius circle at the given coordinates with the given radius.
47 *
48 * The radius is given in pixels.
49 *
50 * @param _x
51 * @param _y
52 * @param _r
53 */
54 public Circle(double _x, double _y, int _r) {
55 x = _x;
56 y = _y;
57 pixRadius = _r;
58 }
59
60 /**
61 * Draws the circle.
62 *
63 * @param panel
64 * @param g
65 */
66 @Override
67public void draw(DrawingPanel panel, Graphics g) {
68 int xpix = panel.xToPix(x)-pixRadius;
69 int ypix = panel.yToPix(y)-pixRadius;
70 g.setColor(color);
71 g.fillOval(xpix, ypix, 2*pixRadius, 2*pixRadius); // draw the circle onto the screen
72 }
73
74 /**
75 * Gets the x coordinate.
76 *

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected