Rotate an image in java by the specified angle

后端 未结 2 857
Happy的楠姐
Happy的楠姐 2020-12-02 01:21

Here\'s the function which draws a shape at the given coordinates:

public void drawTank(int x,int y){
   int h = 50;
   int w = 50;

   graphic.setColor(Col         


        
2条回答
  •  清歌不尽
    2020-12-02 01:58

    Here's the brute-force way to do it. Take a look at Java.lang.Math and java.awt.Graphics (which you already have an instance of) With this you can use the draw polygon function to compute the points of your rectangle, which you can do using the sin and cos functions in Java.lang.Math

    Really, you'd only need to compute two points this way, as your starting point would be the 90degree vertex from which you would calculate the two adjoining coordinates with. From there it's just a matter of doing some addition and subtraction with the points that you have and your dimension values to get the last point kitty-corner to your starting point.

    I'd figure it out for you, and write some example code, but then what fun would that leave you?

提交回复
热议问题