0

im drawing a witch in Java. I finished up with the body and head but now i want to know how I can rotate a rectangle in Java

As you can see on the image below, I need 2 rectangles rotated with a certain degree to visualise the arms of the witch.

Searched for it, but the solutions where too complicated for this.enter image description here

//Body
g.setColor(Blue);
g.fillRect(190, 180, 100, 150);
ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97
Distortion
  • 309
  • 2
  • 3
  • 12

1 Answers1

2

I assume g is an Graphic object then

Graphics2D myGraphics2D = (Graphics2D)g;
myGraphics2D.rotate(3.14159);  //input in rad... read the doc...
ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97
  • Ye it is a graphic object. However your snippet does nothing – Distortion Nov 11 '17 at 13:50
  • 1
    @Distortion: nor does yours. You will want to post your [mcve] so we have more to work with. – Hovercraft Full Of Eels Nov 11 '17 at 13:56
  • https://codepen.io/anon/pen/jaBozp Code i has so far here, but notice it's not working because codepen doesn't support Java. I just put it out from my Netbeans @HovercraftFullOfEels – Distortion Nov 11 '17 at 14:22
  • want to rotate the rectangle 45 degrees let's say – Distortion Nov 11 '17 at 14:23
  • @Distortion: again, create and post your [mcve], else we have no idea what you may be doing wrong or how to help. 1+ to this answer since it **is** correct. If it doesn't work for you, then you're using it wrong, but how? No one can yet say. – Hovercraft Full Of Eels Nov 11 '17 at 14:24
  • I posted my code in codepen and it is minimal,...ofc it works but thats not my point. I didn't rotate the rectangle because I simply dont know HOW TO DO IT. Don't know how it works in Java @HovercraftFullOfEels – Distortion Nov 11 '17 at 14:48
  • 1
    *"I posted my code in codepen"* Post an MCVE as an [edit] to the question here! Some cannot follow external links, others won't, external links might go stale. BTW - @HovercraftFullOfEels, did you notice the subtle trick in specifying `3.14159` as the rotation angle? OP: Do you know the value of Pi? Did you try other values? – Andrew Thompson Nov 11 '17 at 15:33