Search in sources :

Example 6 with GraphicsContext

use of javafx.scene.canvas.GraphicsContext in project Smartcity-Smarthouse by TechnionYP5777.

the class MappingController method drawMapping.

private void drawMapping() {
    final GraphicsContext g = canvas.getGraphicsContext2D();
    g.clearRect(0, 0, canvas.getWidth(), canvas.getHeight());
    g.setStroke(Color.BLACK);
    for (final Room room : house.getRooms()) {
        g.strokeRect(room.x, room.y, room.width, room.height);
        g.strokeLine(room.x, room.y + 20, room.x + room.width, room.y + 20);
        g.setFill(Color.BLACK);
        g.fillText(room.location.name(), room.x + 4, room.y + 15);
        g.setFill(Color.BLUE);
        if (locationsContents.containsKey(room.location)) {
            int dy = 20;
            for (final String id : locationsContents.get(room.location)) {
                g.fillText(" (" + id + ")", room.x + 10, room.y + dy + 20);
                dy += 20;
            }
        }
    }
}
Also used : GraphicsContext(javafx.scene.canvas.GraphicsContext)

Example 7 with GraphicsContext

use of javafx.scene.canvas.GraphicsContext in project aima-java by aimacode.

the class FunctionPlotterCtrl method update.

public void update() {
    GraphicsContext gc = canvas.getGraphicsContext2D();
    gc.clearRect(0, 0, canvas.getWidth(), canvas.getHeight());
    gc.setStroke(Color.GRAY);
    gc.strokeLine(0.01 * canvas.getWidth(), yToScreen(0), canvas.getWidth() * 0.99, yToScreen(0));
    gc.strokeLine(xToScreen(0), 0.01 * canvas.getHeight(), xToScreen(0), 0.99 * canvas.getHeight());
    gc.strokeLine(xToScreen(1), yToScreen(0) - 5, xToScreen(1), yToScreen(0) + 5);
    gc.strokeLine(xToScreen(0) - 5, yToScreen(1), xToScreen(0) + 5, yToScreen(1));
    if (function.isPresent()) {
        gc.setStroke(Color.BLACK);
        double lastVal = function.get().apply(minX);
        for (int i = 1; i < canvas.getWidth(); i++) {
            double newVal = function.get().apply(screenToX(i));
            gc.strokeLine(i - 1, yToScreen(lastVal), i, yToScreen(newVal));
            lastVal = newVal;
        }
    }
}
Also used : GraphicsContext(javafx.scene.canvas.GraphicsContext) Paint(javafx.scene.paint.Paint)

Aggregations

GraphicsContext (javafx.scene.canvas.GraphicsContext)7 SnapshotParameters (javafx.scene.SnapshotParameters)3 Canvas (javafx.scene.canvas.Canvas)3 Image (javafx.scene.image.Image)3 ImagePattern (javafx.scene.paint.ImagePattern)3 LinearGradient (javafx.scene.paint.LinearGradient)3 Stop (javafx.scene.paint.Stop)3 BigDecimal (java.math.BigDecimal)1 Paint (javafx.scene.paint.Paint)1