| 赞 | 68 |
| VIP | |
| 好人卡 | |
| 积分 | 65 |
| 经验 | |
| 最后登录 | 2023-7-2 |
| 在线时间 | 119 小时 |
- 梦石
- 0
- 星屑
- 6483
- 在线时间
- 119 小时
- 注册时间
- 2020-1-8
- 回帖
- 205
|
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有账号?注册会员
×
[pre lang="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
return 0 if 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 < 0 then vH += 360 elsif vH > 360 then vH -= 360 end
vH
end
end
class Bitmap
def draw_scan0(colorA, colorB)
self.set_pixel(0, 0, colorA)
return if self.width == 1
self.set_pixel(0, self.width - 1, colorB)
return if self.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
loop do
bitmap.draw_scan0(red, blue)
break if Time.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}[/pre] |
|