Java Draw Triangle drawTriangle(Graphics2D graphics, double x, double y, double height, double width)

Here you can find the source of drawTriangle(Graphics2D graphics, double x, double y, double height, double width)

Description

draw Triangle

License

Open Source License

Declaration

public static Shape drawTriangle(Graphics2D graphics, double x, double y, double height, double width) 

Method Source Code


//package com.java2s;

import java.awt.Graphics2D;

import java.awt.Shape;

import java.awt.geom.GeneralPath;
import java.awt.geom.Path2D;

public class Main {
    public static Shape drawTriangle(Graphics2D graphics, double x, double y, double height, double width) {
        final GeneralPath triangle = new GeneralPath();
        triangle.setWindingRule(Path2D.WIND_EVEN_ODD);
        triangle.moveTo(x - (width / 2.0), y - (height / 2));
        triangle.lineTo(x + (width / 2.0), y - (height / 2));
        triangle.lineTo(x + (width / 2.0), y + (height / 2));
        triangle.lineTo(x - (width / 2.0), y - (height / 2));
        triangle.closePath();/* w  ww. jav  a 2s.  com*/

        graphics.draw(triangle);

        return triangle;
    }
}

Related

  1. drawTriangle(int x, int y, int size, Graphics2D graphics2D)