examples/spritetest/StarSprite

From FANG

Jump to: navigation, search

01 package examples.spritetest;
02 
03 import java.awt.geom.*;
04 
05 import fang.Sprite;
06 /**
07  * Demonstrates the use of GeneralPath
08  * to make a geometric shape.  The shape
09  * made in this sprite is a star.
10  @author Jam Jenkins
11  */
12 public class StarSprite extends Sprite
13 {
14    /**
15     * makes a symmetric star
16     @param points the number of points
17     @param innerRadius how far in to go for
18     * the non-point vertexes.  1 is all the way
19     * out and will result in a polygon.  0 is all
20     * the way in and will result in invisible
21     * lines for the points.
22     */
23    public StarSprite(int points, double innerRadius)
24    {
25       super();
26       double radius;
27       GeneralPath path=new GeneralPath();
28       int i=0;
29       double angle=i/(points*2.0)*Math.PI*2+1.5*Math.PI;
30       radius=1;
31       float x=(float)(Math.cos(angle)*radius);
32       float y=(float)(Math.sin(angle)*radius);
33       path.moveTo(x, y);
34       for(i=1; i<points*2; i++)
35       {
36          angle=i/(points*2.0)*Math.PI*2+1.5*Math.PI;
37          if(i%2==0)
38             radius=1;
39          else
40             radius=innerRadius;
41          x=(float)(Math.cos(angle)*radius);
42          y=(float)(Math.sin(angle)*radius);
43          path.lineTo(x, y);
44       }
45       path.closePath();
46       setShape(path);
47    }
48 
49 }


Download/View examples/spritetest/StarSprite.java




Views
Personal tools
Add to 
del.icio.usAdd to 
diggAdd to 
FacebookAdd to 
favoritesAdd to 
GoogleAdd to 
MySpaceAdd to 
PrintAdd to 
SlashdotAdd to 
StumbleUponAdd to 
Twitter

Games
Games