用Bitmap#hue_change 模拟 HSL颜色渐变
RUBY 代码class Color
def hue
r, g, b = self.red / 255, self.green / 255, self.blue / 255
max = min = r
if g > max then max = g else min = g end
if b > max then max = b elsif b < min then min = b end
return0if max == min
vH = case max
when r then(g - b) * 60 / (max - min)
when g then(b - r) * 60 / (max - min) + 120
when b then(r - g) * 60 / (max - min) + 240
end
if vH < 0then vH += 360elsif vH > 360then vH -= 360end
vH
end
end
class Bitmap
def draw_scan0(colorA, colorB)
self.set_pixel(0, 0, colorA)
returnifself.width == 1
self.set_pixel(0, self.width - 1, colorB)
returnifself.width == 2
hueA, hueB = colorA.hue, colorB.hue
deltaHue = (hueB - hueA) / (self.width - 1)
hue, pixel = hueA, Bitmap.new(1, 1)
1.upto(self.width - 2)do |i|
pixel.set_pixel(0, 0, colorA)
pixel.hue_change(hue += deltaHue)
self.set_pixel(i, 0, pixel.get_pixel(0, 0))
end
pixel.dispose
end
end
bitmap = Bitmap.new(640, 1)
red = Color.new(255, 0, 0)
blue = Color.new(0, 0, 255)
count, t = 0, Time.now
loopdo
bitmap.draw_scan0(red, blue)
breakifTime.now - t >= 1.0
count += 1
end
print"Bitmap#draw_scan0 => #{count}次/秒"
sprite = Sprite.new
sprite.bitmap = bitmap
sprite.y = 240
sprite.zoom_y = 20
loop{Graphics.update}
本帖来自P1论坛作者RPGzh500223,因Project1站服务器在国外有时候访问缓慢不方便作者交流学习,经联系P1站长fux2同意署名转载一起分享游戏制作经验,共同为国内独立游戏作者共同创造良好交流环境,原文地址:https://rpg.blue/forum.php?mod=viewthread&tid=489134若有侵权,发帖作者可联系底部站长QQ在线咨询功能删除,谢谢。
页:
[1]