JavaFX draw Line - Java JavaFX

Java examples for JavaFX:Shape

Description

JavaFX draw Line

Demo Code


//package com.java2s;
import javafx.geometry.Point2D;
import javafx.scene.image.PixelWriter;
import javafx.scene.paint.Color;

public class Main {
    public static void drawLine(Point2D p1, Point2D p2, Color color,
            PixelWriter pw) {// ww w .jav  a2  s  .c o  m
        double k = (p2.getY() - p1.getY()) / (p2.getX() - p1.getX());
        double y = 0;
        for (int x = (int) p1.getX(); x <= (int) p2.getX(); x++) {
            pw.setColor(x, (int) (y + .5), color);
            y += k;
        }
    }
}

Related Tutorials