class Sprite
alias bitmap_crysse bitmap=
def bitmap=(b)
(@ban= false;@resbitmap = b) if not @ban
bitmap_crysse(b)
end
def apply_bitmap
@resbitmap = self.bitmap
end
def bev(a,d = 2) # 1:上 2:下 3:左 4:右
a = [[-90,a].max,90].min
(return;self.bitmap.clear) if a.abs == 90
k = Math.tan(a/57.3)
c = @resbitmap.height
w = @resbitmap.width
if d<3
nw = c * k + w
@ban = true
self.bitmap = Bitmap.new(nw,c)
if d == 1
c.times{|y|
self.bitmap.blt(y*k,y,@resbitmap,Rect.new(0,y,w,1))
}
else
c.times{|y|
self.bitmap.blt(y*k,c-y,@resbitmap,Rect.new(0,c-y,w,1))
}
end
elsif d>2
nh = w * k + c
@ban = true
self.bitmap = Bitmap.new(w,nh)
if d == 3
w.times{|x|
self.bitmap.blt(x,x*k,@resbitmap,Rect.new(x,0,1,c))
}
else
w.times{|x|
self.bitmap.blt(w-x,x*k,@resbitmap,Rect.new(w-x,0,1,c))
}
end
end
end
end
# 测试代码
s = Sprite.new # 精灵
s.bitmap = Bitmap.new(32,32) # 创建位图
s.bitmap.fill_rect(0,0,32,32,Color.new(255,0,0)) # 填充矩形
a = 30 # 设置斜切角度
s.bev(a,4) # 以设定的角度,右边为起始进行斜切
s.apply_bitmap # 替换内部存储的位图以供二次切帖
s.bev(a,2) # 以设定的角度,下边为起始进行斜切
loop{Graphics.update} # 返回结果
class Sprite
alias bitmap_crysse bitmap=
def bitmap=(b)
(@ban= false;@resbitmap = b) if not @ban
bitmap_crysse(b)
end
def apply_bitmap
@resbitmap = self.bitmap
end
def bev(a,d = 2) # 1:上 2:下 3:左 4:右
a = [[-90,a].max,90].min
(return;self.bitmap.clear) if a.abs == 90
k = Math.tan(a/57.3)
c = @resbitmap.height
w = @resbitmap.width
if d<3
nw = c * k + w
@ban = true
self.bitmap = Bitmap.new(nw,c)
if d == 1
c.times{|y|
self.bitmap.blt(y*k,y,@resbitmap,Rect.new(0,y,w,1))
}
else
c.times{|y|
self.bitmap.blt(y*k,c-y,@resbitmap,Rect.new(0,c-y,w,1))
}
end
elsif d>2
nh = w * k + c
@ban = true
self.bitmap = Bitmap.new(w,nh)
if d == 3
w.times{|x|
self.bitmap.blt(x,x*k,@resbitmap,Rect.new(x,0,1,c))
}
else
w.times{|x|
self.bitmap.blt(w-x,x*k,@resbitmap,Rect.new(w-x,0,1,c))
}
end
end
end
end
# 测试代码
s = Sprite.new # 精灵
s.bitmap = Bitmap.new(32,32) # 创建位图
s.bitmap.fill_rect(0,0,32,32,Color.new(255,0,0)) # 填充矩形
a = 30 # 设置斜切角度
s.bev(a,4) # 以设定的角度,右边为起始进行斜切
s.apply_bitmap # 替换内部存储的位图以供二次切帖
s.bev(a,2) # 以设定的角度,下边为起始进行斜切
loop{Graphics.update} # 返回结果