Java Graphics Draw Border drawDirectionalTriangle(Graphics2D bbg, double heading, double x, double y, double sideLength, Color fillColor, Color borderColor)

Here you can find the source of drawDirectionalTriangle(Graphics2D bbg, double heading, double x, double y, double sideLength, Color fillColor, Color borderColor)

Description

Draws a directional triangle on a graphics 2D

License

Open Source License

Parameter

Parameter Description
bbg The graphics2D object
heading The direction its heading in radians
x The x coordinate
y The y coordinate
sideLength The length of the longest two sides
fillColor The color of the body of the triangle
borderColor The border color of the triangle

Declaration

public static void drawDirectionalTriangle(Graphics2D bbg, double heading, double x, double y,
        double sideLength, Color fillColor, Color borderColor) 

Method Source Code


//package com.java2s;
/*//from  w w  w .j a  va 2  s .com
 * The Bio-inspired Leadership Toolkit is a set of tools used to simulate the
 * emergence of leaders in multi-agent systems. Copyright (C) 2014 Southern
 * Nazarene University This program is free software: you can redistribute it
 * and/or modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation, either version 3 of the License,
 * or at your option) any later version. This program is distributed in the hope
 * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details. You should have received a copy of
 * the GNU General Public License along with this program. If not, see
 * <http://www.gnu.org/licenses/>.
 */

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Polygon;

public class Main {
    /**
     * Draws a directional triangle on a graphics 2D
     * 
     * @param bbg The graphics2D object
     * @param heading The direction its heading in radians
     * @param x The x coordinate
     * @param y The y coordinate
     * @param sideLength The length of the longest two sides
     * @param fillColor The color of the body of the triangle
     * @param borderColor The border color of the triangle
     */
    public static void drawDirectionalTriangle(Graphics2D bbg, double heading, double x, double y,
            double sideLength, Color fillColor, Color borderColor) {
        Polygon triangle = new Polygon();

        // add a point straight ahead and slightly longer than side length
        triangle.addPoint(0, (int) (1.5 * sideLength));
        // add the two side points slightly off to the right and left of center
        triangle.addPoint((int) (sideLength / 2), 0);
        triangle.addPoint((int) (-sideLength / 2), 0);

        // move the origin of drawing to the x and y coordinate to be drawn
        bbg.translate(x, y);
        // rotate the g2d object by heading
        bbg.rotate(heading);

        // set the fill color and draw
        bbg.setColor(fillColor);
        bbg.fill(triangle);
        // set the border color and draw
        bbg.setColor(borderColor);
        bbg.draw(triangle);

        // undo the transformations
        bbg.rotate(-heading);
        bbg.translate(-x, -y);
    }
}

Related

  1. drawBevel3DBorder(Graphics g, int x, int y, int w, int h, Color highlight, Color shadow, Color innerHighlight, Color innerShadow)
  2. drawBorder(Graphics g, Color c, int x, int y, int w, int h)
  3. drawBorder(Graphics2D g2d, Color borderColor, int x, int y, int width, int height)
  4. drawButtonBorder(Graphics g, int x, int y, int w, int h, Color backgroundColor, Color edgeColor, Color cornerColor)
  5. drawEtchedBorder(Graphics g, int x, int y, int width, int height, Color dark, Color bright)
  6. drawHighlightBorder(Graphics g, int x, int y, int width, int height, boolean raised, Color shadow, Color highlight)
  7. drawSquareBorder(Graphics2D g, int x, int y, int width, int height, int rounding, Color color, float strokeWidth)
  8. paintBorder(Graphics g, int borderType, Insets insets, Color[] colors, int width, int height)