/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * AndroidWorld Library, Copyright 2011 Bryan Chadwick * * * * FILE: ./android/image/Star.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; /** * * * Represents an Image of a Star. There are several constructors to support customization * with number of points, and inner/outer radius. * *
 *    new Star(40, 5, "solid", "gray")
* *
* *
 *    new Star(30, 7, "outline", "red")
* *
* *
 *    new Star(40, 30, 10, "solid", "cornflowerblue")
* *
* */ public class Star extends RegularPolygon{ private static double RadScale = 0.4; /** Create a Star Image with (double) radius, mode and color */ public Star(double radius, String mode, String color){ this(radius,radius*RadScale,5,mode,color); } /** Create a Star Image with (int) radius, mode and color */ public Star(int radius, String mode, String color){ this(radius,radius*RadScale,5,mode,color); } /** Create a Star Image with (double) radius, sides, mode and color */ public Star(double radius, int sides, String mode, String color){ this(radius,radius*RadScale,sides,mode,color); } /** Create a Star Image with (int) radius, sides, mode and color */ public Star(int radius, int sides, String mode, String color){ this(radius,radius*RadScale,sides,mode,color); } /** Create a Star Image with (double) radius, inner-radius, sides, mode and color */ public Star(double radius, double innerRad, int sides, String mode, String color){ this((int)round(radius),round(innerRad),sides,mode,color); } /** Create a Star Image with (int) radius, inner-radius, sides, mode and color */ public Star(int radius, int innerRad, int sides, String mode, String color){ this(radius,innerRad,sides,mode(mode),color(color)); } /** Create a Star with converted mode and color */ protected Star(int radius, int innerRad, int sides, int mode, int color){ super(make(radius, innerRad, sides), mode, color); } private static Path make(int radius, double inrad, int sides){ Path poly = new Path(); double first = 3*Math.PI/2, mult = Math.PI/sides; poly.moveTo((int)(radius*Math.cos(first)), (int)(radius*Math.sin(first))); for(int i = 2; i <= sides*2; i+=2){ poly.lineTo((int)(inrad*Math.cos(first+(i-1)*mult)), (int)(inrad*Math.sin(first+(i-1)*mult))); poly.lineTo((int)(radius*Math.cos(first+(i)*mult)), (int)(radius*Math.sin(first+(i)*mult))); } poly.close(); return poly; } }