One approach is shown in SineTest
. In outline,
-
Save the graphics context’s transform.
Graphics2D g2d = (Graphics2D) g; AffineTransform at = g2d.getTransform();
-
Translate the origin to the center.
g2d.translate(w / 2, h / 2);
-
Invert the y-axis.
g2d.scale(1, -1);
-
Render using cartesian coordinates.
-
Restore the transform for conventional rendering.
g2d.setTransform(at);