Grid.java
import javafx.scene.Group; import javafx.scene.*; import javafx.scene.paint.*; import javafx.scene.shape.*; import javafx.collections.*; public class Grid { public static void draw(Group grp) { double res = grp.getScaleX(); Color c = Color.rgb(220,200,255); // shape 1 in Grid Rectangle r = new Rectangle(-4.0,-4.0,8.0,8.0); r.setFill(Color.TRANSPARENT); r.setStroke(Color.BLACK); r.setStrokeWidth(1/res); // grid lines (shape 2) double u = 4.0; Path p1 = new Path(); ObservableList<PathElement> p = p1.getElements(); for (int i=-4; i<=4; i++) { double v = i; p.add(new MoveTo(-u,v)); p.add(new LineTo(u,v)); p.add(new MoveTo(v,-u)); p.add(new LineTo(v,u)); } p1.setStrokeWidth(1.0/res); p1.setStroke(c); // locate origin (shape 3) Path p2 = new Path(); p = p2.getElements(); u = 0.05; p.add(new MoveTo(-u,u)); p.add(new LineTo(u,-u)); p.add(new MoveTo(-u,-u)); p.add(new LineTo(u,u)); p2.setStrokeWidth(1.0/res); ObservableList<Node> ol = grp.getChildren(); ol.addAll(r,p1,p2); } }
Maintained by John Loomis, updated Mon Mar 05 12:00:23 2018