draw Spline - Java 2D Graphics

Java examples for 2D Graphics:Line

Description

draw Spline

Demo Code

// Copyright (C)1996,1998 by Jef Poskanzer <jef@mail.acme.com>.  All rights reserved.
//package com.java2s;
import java.awt.*;

public class Main {
    private static final int SPLINE_THRESH = 3;

    public static void drawSpline(Graphics graphics, int x1, int y1,
            int x2, int y2, int x3, int y3) {
        int xa, ya, xb, yb, xc, yc, xp, yp;

        xa = (x1 + x2) / 2;/*from w  w w  . j  a  v  a2s.  com*/
        ya = (y1 + y2) / 2;
        xc = (x2 + x3) / 2;
        yc = (y2 + y3) / 2;
        xb = (xa + xc) / 2;
        yb = (ya + yc) / 2;

        xp = (x1 + xb) / 2;
        yp = (y1 + yb) / 2;
        if (Math.abs(xa - xp) + Math.abs(ya - yp) > SPLINE_THRESH)
            drawSpline(graphics, x1, y1, xa, ya, xb, yb);
        else
            graphics.drawLine(x1, y1, xb, yb);

        xp = (x3 + xb) / 2;
        yp = (y3 + yb) / 2;
        if (Math.abs(xc - xp) + Math.abs(yc - yp) > SPLINE_THRESH)
            drawSpline(graphics, xb, yb, xc, yc, x3, y3);
        else
            graphics.drawLine(xb, yb, x3, y3);
    }
}

Related Tutorials