Subato

Star in Swing

package name.panitz.oose;

public class Star extends PolygonObject {
  int beams;
  double innerRadius;
  
  public Star(int beams,double innerRadius,Vertex corner, double width, Vertex velocity) {
    super(corner, width, width, velocity);
    this.beams = beams;
    this.innerRadius = innerRadius;
    initPolygon();
  }
  @Override
  public String toString() {
    return "new Star("+beams+", "+innerRadius+", new Vertex"+corner+", "+width+", new Vertex"+velocity+")";
  }

  @Override
  void initPolygon() {
    double radius = width/2;
    double alpha = Math.PI*2/beams;
    for (int i = 0;i<beams;i++){
      p.add(radius+Math.cos(i*alpha)*radius,radius+Math.sin(i*alpha)*radius);
      p.add(radius+Math.cos(i*alpha+alpha/2)*innerRadius,radius+Math.sin(i*alpha+alpha/2)*innerRadius);
    }
  }
}