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

Method draw

src/org/opensourcephysics/display/Arrow.java:161–175  ·  view source on GitHub ↗

Draws the arrow. @param panel the drawing panel in which the arrow is viewed @param g the graphics context upon which to draw

(DrawingPanel panel, Graphics g)

Source from the content-addressed store, hash-verified

159 * @param g the graphics context upon which to draw
160 */
161 @Override
162public void draw(DrawingPanel panel, Graphics g) {
163 Graphics2D g2 = (Graphics2D) g;
164 AffineTransform tr = panel.getPixelTransform();
165 g2.setPaint(color);
166 // draw the shaft
167 g2.draw(tr.createTransformedShape(new Line2D.Double(x, y, x+a, y+b)));
168 ptA.setLocation(x+a, y+b);
169 tr.transform(ptA, ptA);
170 double aspect = panel.isSquareAspect() ? 1 : -tr.getScaleX()/tr.getScaleY();
171 Shape temp = getHead(ptA, Math.atan2(b, aspect*a));
172 // draw the head
173 g2.fill(temp);
174 g2.setPaint(Color.BLACK);
175 }
176
177 private double lastTheta = java.lang.Double.NaN, lastX, lastY, lastHeadSize;
178 private Shape head;

Callers

nothing calls this directly

Calls 10

getHeadMethod · 0.95
getPixelTransformMethod · 0.80
setPaintMethod · 0.80
getScaleXMethod · 0.80
getScaleYMethod · 0.80
drawMethod · 0.65
isSquareAspectMethod · 0.65
setLocationMethod · 0.45
transformMethod · 0.45
fillMethod · 0.45

Tested by

no test coverage detected