/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * AndroidWorld Library, Copyright 2011 Bryan Chadwick * * * * FILE: ./android/image/Triangle.java * * * * This file is part of AndroidWorld. * * * * AndroidWorld 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. * * * * AndroidWorld 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 AndroidWorld. If not, see . * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ package android.image; import android.graphics.Path; import android.graphics.Canvas; import android.graphics.Paint; /** * * * Represents an Image of a Triangle. * *
 *    new Triangle(40, "solid", "tan")
* *
* *
 *    new Triangle(60, "outline", "purple")
* *
* */ public class Triangle extends Image{ int height; int mode; Paint paint; Path path; /** Create a Triangle Image with (double) height, mode and color */ public Triangle(double height, String mode, String color){ this(round(height),mode,color); } /** Create a Triangle Image with (int) height, mode and color */ public Triangle(int height, String mode, String color){ this(height,mode(mode),color(color)); } /** Create a Rectangle with converted mode and color */ private Triangle(int height, int mode, int color){ super(height/2, height/2); this.height = height; this.mode = mode; this.paint = painter(color,mode); this.path = new Path(); path.moveTo(0, -height/2); path.lineTo(height/2, height/2); path.lineTo(-height/2, height/2); path.close(); } /** Paint this Scene into the given graphics */ public void paint(Canvas c, int x, int y){ Path t = new Path(path); t.offset(x, y); c.drawPath(t, paint); } /** Return the Width of this Image */ public int width(){ return height; } /** Return the Height of this Image */ public int height(){ return height; } }