aspose file tools*
The moose likes Java in General and the fly likes Scale a shape with center as orgin Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Scale a shape with center as orgin" Watch "Scale a shape with center as orgin" New topic
Author

Scale a shape with center as orgin

Kalle Zander
Greenhorn

Joined: Nov 16, 2010
Posts: 28


I want the shape to pulse in size on its coordinates x and y, but this is also "moving" the shape diagonally back and to when scaling. How do I avoid the moving? A bit bad explained but I hope you understand what I mean.

Is AffineTransform useful to use here in some way?

//Kalle


Code first, then think.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4664
    
    5

I want the shape to pulse in size on its coordinates x and y

Then you need to translate the origin back after scaling.


luck, db
There are no new questions, but there may be new answers.
Kalle Zander
Greenhorn

Joined: Nov 16, 2010
Posts: 28
Darryl Burke wrote:
I want the shape to pulse in size on its coordinates x and y

Then you need to translate the origin back after scaling.


Thank you, that did it!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40034
    
  28
I suggest you use a copy of the Graphics object, obtained with the (??) Graphics#create() method, to apply those transformations to.
Kalle Zander
Greenhorn

Joined: Nov 16, 2010
Posts: 28
Campbell Ritchie wrote:I suggest you use a copy of the Graphics object, obtained with the (??) Graphics#create() method, to apply those transformations to.


Yes I use a copy of the Graphics2D object as argument in that draw method, otherwise would other sprites rotate, scale etc the same way as that sprite which is not wanted.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40034
    
  28
Sprites drawn after the rotation would also be rotated. If you try to reverse the transform, tiny rounding errors will be introduced, and there will be slight distortions of the display. That is seen worst after shearing. So it is probably better to copy the Graphics object.
Kalle Zander
Greenhorn

Joined: Nov 16, 2010
Posts: 28
Campbell Ritchie wrote:Sprites drawn after the rotation would also be rotated. If you try to reverse the transform, tiny rounding errors will be introduced, and there will be slight distortions of the display. That is seen worst after shearing. So it is probably better to copy the Graphics object.


What do you mean by copying in this case then, not like I meant?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40034
    
  28
Kalle Zander wrote: . . . What do you mean by copying in this case then, not like I meant?
I obviously wasn't clear. I was agreeing with you, and explaining potential problems if you don't use a copy.
Kalle Zander
Greenhorn

Joined: Nov 16, 2010
Posts: 28
Campbell Ritchie wrote:
Kalle Zander wrote: . . . What do you mean by copying in this case then, not like I meant?
I obviously wasn't clear. I was agreeing with you, and explaining potential problems if you don't use a copy.


Ah, ok sorry. I thought you wasn't agreeing and referred to something else. Nevermind.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40034
    
  28
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Scale a shape with center as orgin