Download java source from src.zip
The idea is to create a grid (1 unit per division) instead of using pixel coordinates.
The Swing version is shown in
The plan now is to use JavaFX Group objects. The plan is to use Shape objects, such as Line and Path instead of graphics generated by a GraphicsContext object.
We use transformations to convert from pixel coordinates to grid coordinates.
All transformations are located in the
javafx.scene.transform package and are subclasses of the
The relevant code is as follows:
Group grp = new Group(); Scene scene = new Scene(grp, 400, 400); Translate tr = new Translate(scene.getWidth()/2,scene.getHeight()/2); int res = 48; //98; Scale scl = new Scale(res,res); grp.getTransforms().addAll(tr,scl);
Here we use the internal transformation properties defined in Node, which is in the parent tree for Group. These seem more appropriate for GUI uses.
The relevant code follows:
Group grp = new Group(); Scene scene = new Scene(grp, 400, 400); grp.setTranslateX(scene.getWidth()/2); grp.setTranslateY(scene.getHeight()/2); double res = 48; //98; grp.setScaleX(res); grp.setScaleY(res); grp.setRotate(10.0);
This first version is a standalone program that draws a capacitor, using a Path object. It derives from an earlier AWT/Swing version capacitor.java
Capacitor2.java and MyCap.java
The second version uses a separate capacitor class which constructs a Group and adds it to the parent group.
Here we superimpose two instances of
Capacitor2 over the parent grid.
Here we replace the Line objects in the grid with a couple of Path objects.
Separate the grid draw function to another class.
Try to draw an inductor. Unfortunately, the drawing is not centered correctly.
Test hypothesis that group objects must be symmetric about the origin.
Rewrite the inductor drawing so that it is symmetric about the origin.
Maintained by John Loomis, last updated 18 April 2017