Project1
标题:
有关Bitmap#blur的改进
[打印本页]
作者:
精灵使者
时间:
2013-9-15 08:09
标题:
有关Bitmap#blur的改进
#=============================================================================
# ■ Bitmap重定义
#=============================================================================
class Bitmap
def blur(strength = 1, opacity = 10)
(-strength).upto(strength) do |x|
(-strength).upto(strength) do |y|
next if x.zero? and y.zero?
src_rect = Rect.new(0, 0, width - x, height - y)
blt(x, y, self, src_rect, opacity)
end
end
end
end
复制代码
这个blur如果反复递归的话会出现bitmap大小越来越大(也就是黑边填充)的现象。
求改进,求更新
顺便召唤
@忧雪の伤
作者:
R-零
时间:
2013-9-15 10:44
#=============================================================================
# ■ Bitmap重定义
#=============================================================================
class Sprite
alias ud update
def update
self.bitmap = self.bitmap.exc
ud
end
end
class Bitmap
def blur(strength = 1, opacity = 5)
blur_in(strength, opacity)
extend(strength,strength,strength,strength)
end
def exc
return self if not @excb
self.dispose
return @excb
end
def blur_in(strength = 1, opacity = 10)
(-strength).upto(strength) do |x|
(-strength).upto(strength) do |y|
next if x.zero? and y.zero?
src_rect = Rect.new(0, 0, width - x, height - y)
blt(x, y, self, src_rect, opacity)
end
end
end
def extend(lx,ly,rx,ry)
new_bitmap = Bitmap.new(width+lx+rx,height+ly+ry)
new_bitmap.blt(lx,ly,self,Rect.new(0, 0, width, height))
@excb = new_bitmap
end
end
s = Sprite.new
s.bitmap = Bitmap.new(32,32)
s.bitmap.fill_rect(0,0,32,32,Color.new(255,0,0))
s.x = 320
s.y = 240
s.ox = s.bitmap.width / 2
s.oy = s.bitmap.height / 2
loop{Graphics.update;s.update;s.bitmap.blur;s.ox = s.bitmap.width / 2;
s.oy = s.bitmap.height / 2
}
复制代码
边blur边扩充边缘
不过这个东西还不够卫生不能多用
欢迎光临 Project1 (https://rpg.blue/)
Powered by Discuz! X3.1