• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Rotating a Graphic

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello guys, I want to make a Graphic rotating, but don't know how.
I'm using GeneralPaths, and already wrote this:


The result is a blue square, and I only need a formula for rotating the corners of p.
 
Marshal
Posts: 76879
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you mean that you rotate it the way a sheet of paper would rotate while lying on the table?
I suggest you try affine transforms on the Graphics object. Somebody else asked a similar question last week, so you could adapt what I said here, by using the rotate() method. It is worth finding out whether you rotate in degrees or radians, and whether it is clockwise or anticlockwise.
 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also you shouldn't put a sleep in the paintComponent method or the GUI will just hang. If you want to repaint at a regular interval use a Timer to call repaint every n milliseconds.
 
Bartender
Posts: 825
5
Python Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should cast your Graphics to Graphics2D at the beginning of your method and work with it.

To apply rotation (or even some other transformation) on your coordinates, you should check the AffineTransform API for more information. For your requirement:

In case you want to apply transformation just temporary, you can get old transformation that will be set back after the one you're doing:
 
No thanks. We have all the government we need. This tiny ad would like you to leave now:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic