/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 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 <http://www.gnu.org/licenses/>. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ package android.image; import android.graphics.Path; /** * <style type='text/css'><!-- * .com{ font-style: italic; color: #880000; } * .keyw{ font-weight: bold; color: #000088; } * .num{ color: #00AA00; } * .str{ color: #CC00AB; } * .prim{ color: #0000FF; } * img.example{ padding-left: 50px; padding-bottom: 30px; } * --></style> * * Represents an Image of a Star. There are several constructors to support customization * with number of points, and inner/outer radius. * * <pre> * <span class='keyw'>new</span> Star(<span class='num'>40</span>, <span class='num'>5</span>, <span class='str'>"solid"</span>, <span class='str'>"gray"</span>)</pre> * <img class="example" src="test/images/star-1.png" /> * <br /> * * <pre> * <span class='keyw'>new</span> Star(<span class='num'>30</span>, <span class='num'>7</span>, <span class='str'>"outline"</span>, <span class='str'>"red"</span>)</pre> * <img class="example" src="test/images/star-2.png" /> * <br /> * * <pre> * <span class='keyw'>new</span> Star(<span class='num'>40</span>, <span class='num'>30</span>, <span class='num'>10</span>, <span class='str'>"solid"</span>, <span class='str'>"cornflowerblue"</span>)</pre> * <img class="example" src="test/images/star-3.png" /> * <br /> * */ 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; } }