1

can anyone tell me how to rotate the inner yellow star within the blue star

import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Path2D;

public class app extends Applet
{
   final static int OFFSET = 30;
   final static int OFFSETS = 30;

   public void paint(Graphics g)
   {
      Graphics2D g2 = (Graphics2D) g;
      int width = getWidth()-2*OFFSET;
      int height = getHeight()-2*OFFSET;
      g2.translate(width/2-height/2+OFFSETS, OFFSETS);
      width = height;
      g2.setColor(Color.white);
      setBackground(Color.white);
      Path2D star = new Path2D.Float();
      star.moveTo(width/5F, height-1);
      star.lineTo(width/2F, 0);
      star.lineTo(4*width/5F, height-1);
      star.lineTo(0, 2*height/5F);
      star.lineTo(width-1, 2*height/5F);
      star.closePath();
      g2.draw(star);
      g2.setColor(Color.blue);
      g2.fill(star);
      
   ////////////////////////// inner star//////////////////////////////////  


      int widths = getWidth()-3*90;
      int heights = getHeight()-3*37;
      g2.translate(widths/2-heights/2+OFFSETS, OFFSETS);
      widths = heights;      
      g2.setColor(Color.white);
      setBackground(Color.white);
      Path2D star1 = new Path2D.Float();
      star1.moveTo(widths/5F, heights-1);
      star1.lineTo(widths/2F, 0);
      star1.lineTo(4*widths/5F, heights-1);
      star1.lineTo(0, 2*heights/5F);
      star1.lineTo(widths-1, 2*heights/5F);
      star1.closePath();
      g2.draw(star1);
      g2.setColor(Color.yellow);
      g2.fill(star1);
   }
}
3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by Ezzaral
1

You could use the transform(AffineTransform at) method on your Path2D star1, with an AffineTransform obtained from AffineTransform.getRotateInstance(double theta, double anchorx, double anchory) to rotate it by any desired angle

AffineTransformations look very scary, and often they are, but in essence they take a shape and change it by stretching, skewing, sheering, rotating etc. All you need is a simple rotation, which the method I suggested will give you.

API documentation is in the usual place.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.