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

Class Spring

src/org/opensourcephysics/display/Spring.java:22–356  ·  view source on GitHub ↗

Draws a coil spring in a drawing panel. @author F. Esquembre @author W. Christian @version 1.0

Source from the content-addressed store, hash-verified

20 * @version 1.0
21 */
22public class Spring implements Measurable {
23 private GeneralPath springPath = new GeneralPath();
24 // Configuration variables
25 protected boolean thinExtremes = true;
26 protected boolean visible = true;
27 protected int loops = -1, pointsPerLoop = -1; // -1 to make sure the arrays are allocated
28 protected float x = 0.0f, y = 0.0f;
29 protected float sizex = 0.1f, sizey = 0.0f;
30
31 /**
32 * The radius of the spring (normal to its direction)
33 */
34 protected float radius = 0.1f;
35 protected float solenoid = 0.0f;
36 protected Color edgeColor = Color.BLACK;
37 protected Stroke edgeStroke = new BasicStroke(1.0f);
38 // Implementation variables
39 protected boolean hasChanged = true, zeroLength = false; // Whether the element should recompute data that depends on position, size, scale, resolution, ...
40 private int segments = 0;
41 private float xPoints[] = null, yPoints[] = null;
42
43 /**
44 * Constructs a 0.1 radius Spring.
45 */
46 public Spring() {
47 this(0.1);
48 }
49
50 /**
51 * Special constructor that allows to specify the radius of the spring
52 * @param _radius the radius of the spring (normal to its direction)
53 */
54 public Spring(double _radius) {
55 setRadius(_radius);
56 setResolution(8, 15);
57 }
58
59 // -------------------------------------
60 // Configuration methods
61 // -------------------------------------
62
63 /**
64 * Sets the X position of the origin of the spring
65 * @param x double
66 */
67 public void setX(double x) {
68 this.x = (float) x;
69 hasChanged = true;
70 }
71
72 /**
73 * Gets the X position of the origin of the spring
74 * @return double
75 */
76 public double getX() {
77 return this.x;
78 }
79

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected