Neo-Bahamut
Member
I tried to write a method to rotate Bitmaps:
But it has some errors.
First, the rotated Bitmap is larger than it should be (for example a 100x100 Bitmap which is rotated by 90° is 200x200 big after that)
And some parts of the Bitmap are cut off (http://img200.imageshack.us/img200/9483/screenpsw.png)
I hope someone can help me :3
Code:
class Bitmap
#--------------------------------------------------------------------------
# * Returns a rotated Bitmap
# degree: The angle of rotation.
#--------------------------------------------------------------------------
def rotate(degree)
angle = (degree*Math::PI) / 180
cos = Math.cos(angle)
sin = Math.sin(angle)
point_x = [0, height*sin, width*cos - height*sin, width*cos]
point_y = [0, height*cos, height*cos - width*sin, width*sin]
min_x = point_x.min
max_x = point_x.max
min_y = point_y.min
max_y = point_y.max
w = max_x.abs - min_x
h = max_y.abs - min_y
bitmap = Bitmap.new(w.ceil, h.ceil)
for x in 0...bitmap.width
for y in 0...bitmap.height
source_x = (x+min_x)*cos + (y+min_y)*sin
source_y = (y+min_y)*cos - (x+min_y)*sin
bitmap.set_pixel(x, y, get_pixel(source_x, source_y))
end
end
bitmap
end
end
But it has some errors.
First, the rotated Bitmap is larger than it should be (for example a 100x100 Bitmap which is rotated by 90° is 200x200 big after that)
And some parts of the Bitmap are cut off (http://img200.imageshack.us/img200/9483/screenpsw.png)
I hope someone can help me :3