java - JavaFX Line segment width -


i have code responds key presses, , draws points , line segments correspondingly. however, width of line segments seems alternate, though don't touch line stroke width in code. i'm wondering why happening.

here code:

import javafx.application.application; import javafx.scene.scene; import javafx.scene.layout.pane; import javafx.scene.paint.color; import javafx.scene.shape.rectangle; import javafx.stage.stage; import javafx.scene.shape.line;  public class drawlinesegments extends application {      static double x = 0.0;     static double y = 0.0;      public static void main(string[] args) {         application.launch(args);     }      @override     public void start(stage primarystage) throws exception {          pane p = new pane();          rectangle border = new rectangle(0, 0, 300, 100);         border.setfill(color.transparent);         rectangle initialpoint = new rectangle(border.getwidth() / 2, border.getheight() / 2, 2, 2);         initialpoint.setfill(color.black);          x = border.getwidth() / 2;         y = border.getheight() / 2;          p.getchildren().addall(border, initialpoint);          p.setonkeypressed(e -> {              switch (e.getcode()) {              case :                  line upline = new line(x + 1, y + 1, x + 1, y + 1 - 7.5);                 y = y - 7.5;                 upline.setstroke(color.blueviolet);                 upline.setfill(color.sandybrown);                 p.getchildren().add(upline);                 p.getchildren().add(new rectangle(x, y, 2, 2));                 break;              case down :                  line downline = new line(x + 1, y + 1, x + 1, y + 1 + 7.5);                 y = y + 7.5;                 downline.setstroke(color.blueviolet);                 downline.setfill(color.sandybrown);                 p.getchildren().add(downline);                 p.getchildren().add(new rectangle(x, y, 2, 2));                 break;              case left :                  line leftline = new line(x - 7.5, y + 1, x + 1, y + 1);                 x = x - 7.5;                 leftline.setstroke(color.blueviolet);                 leftline.setfill(color.sandybrown);                 p.getchildren().add(leftline);                 p.getchildren().add(new rectangle(x, y, 2, 2));                 break;              case right :                  line rightline = new line(x + 7.5, y + 1, x + 1, y + 1);                 x = x + 7.5;                 rightline.setstroke(color.blueviolet);                 rightline.setfill(color.sandybrown);                 p.getchildren().add(rightline);                 p.getchildren().add(new rectangle(x, y, 2, 2));                 break;              default:                 break;             }         });          scene scene = new scene(p);          primarystage.setscene(scene);         primarystage.settitle("draw line segments");         primarystage.show();          p.requestfocus();      }  } 

and image perhaps better explains i'm asking:

enter image description here

you may want read on coordinate system of node

coordinate system

the node class defines traditional computer graphics "local" coordinate system in x axis increases right , y axis increases downwards. concrete node classes shapes provide variables defining geometry , location of shape within local coordinate space. example, rectangle provides x, y, width, height variables while circle provides centerx, centery, , radius.

at device pixel level, integer coordinates map onto corners , cracks between pixels , centers of pixels appear @ midpoints between integer pixel locations. because coordinate values specified floating point numbers, coordinates can precisely point these corners (when floating point values have exact integer values) or location on pixel. example, coordinate of (0.5, 0.5) point center of upper left pixel on stage. similarly, rectangle @ (0, 0) dimensions of 10 10 span upper left corner of upper left pixel on stage lower right corner of 10th pixel on 10th scanline. pixel center of last pixel inside rectangle @ coordinates (9.5, 9.5).

regarding problem: don't use 7.5. instead use 7 or 8.


Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -