Java Graphics Draw drawCube(Graphics g, int x, int y, int w, int h, int d, float fac)

Here you can find the source of drawCube(Graphics g, int x, int y, int w, int h, int d, float fac)

Description

draw Cube

License

Open Source License

Declaration

public static void drawCube(Graphics g, int x, int y, int w, int h, int d, float fac) 

Method Source Code

//package com.java2s;
/*************************************************************************
 * Clus - Software for Predictive Clustering                             *
 * Copyright (C) 2007                                                    *
 *    Katholieke Universiteit Leuven, Leuven, Belgium                    *
 *    Jozef Stefan Institute, Ljubljana, Slovenia                        *
 *                                                                       *
 * 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/>. *
 *                                                                       *
 * Contact information: <http://www.cs.kuleuven.be/~dtai/clus/>.         *
 *************************************************************************/

import java.awt.*;

public class Main {
    public static void drawCube(Graphics g, int x, int y, int w, int h, int d, float fac) {
        int dx = (int) ((float) d * fac);
        int dy = (int) ((float) d * (1 - fac));
        Color color = g.getColor();
        g.fillRect(x, y, w + 1, h + 1);// w w w.j  ava 2 s. c o  m
        g.setColor(color.darker());
        Polygon p1 = makeParalRect(x + w, y + h, x + w, y, x + w + dx, y + h - dy);
        Polygon p2 = makeParalRect(x, y, x + dx, y - dy, x + w, y);
        g.fillPolygon(p1);
        g.fillPolygon(p2);
        g.setColor(color);
        g.drawPolygon(p1);
        g.drawPolygon(p2);
    }

    public static Polygon makeParalRect(int x1, int y1, int x2, int y2, int x3, int y3) {
        int x4, y4;
        Polygon p = new Polygon();
        p.addPoint(x1, y1);
        p.addPoint(x2, y2);
        x4 = x2 + x3 - x1;
        y4 = y2 + y3 - y1;
        p.addPoint(x4, y4);
        p.addPoint(x3, y3);
        return p;
    }
}

Related

  1. drawCheckerPattern(Graphics g_, int checkerSize)
  2. drawColors(Color[] colors, Graphics g, int x1, int y1, int x2, int y2, int direction)
  3. drawCoordinateAxes(Graphics2D g, Component comp)
  4. drawCross(Graphics2D g2d, int x, int y, int size)
  5. drawCrosshatch(Graphics2D g, Color color, int left, int right, int top, int height, int spacing, int verticalOffset)
  6. drawDiamond(Graphics2D g2d, int xPos, int yPos)
  7. drawDisc(Graphics g)
  8. drawDot(Graphics g, int x, int y)
  9. drawDots(Graphics g, int x0, int y0, int x1, int y1, int interval)