赞 | 0 |
VIP | 0 |
好人卡 | 0 |
积分 | 1 |
经验 | 28405 |
最后登录 | 2017-12-29 |
在线时间 | 241 小时 |
Lv1.梦旅人
- 梦石
- 0
- 星屑
- 75
- 在线时间
- 241 小时
- 注册时间
- 2013-3-28
- 帖子
- 67
|
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
方法十分简陋,而且很难看
效率嘛……不要管它好了
class Bitmap def gradient_fill_rect(*args) case args[0].size when 7 x, y, width, height, color1, color2, vertical = args[0] when 6 x, y, width, height, color1, color2, vertical = args[0] + [false] when 4 rect, color1, color2, vertical = args[0] when 3 rect, color1, color2 = args[0] + [false] end if rect != nil x, y, width, height = rect.x, rect.y, rect.width, rect.height end if !vertical for i in x..x+width color_r = ((color1.red-color2.red)*(i-x).to_f/width + color1.red) color_g = ((color1.green-color2.green)*(i-x).to_f/width + color1.green) color_b = ((color1.blue-color2.blue)*(i-x).to_f/width + color1.blue) color = Color.new(color_r, color_g, color_b) fill_rect(i, y, 1, height, color) end else for i in y..y+height color_r = ((color1.red-color2.red)*(i-y).to_f/height + color1.red) color_g = ((color1.green-color2.green)*(i-y).to_f/height + color1.green) color_b = ((color1.blue-color2.blue)*(i-y).to_f/height + color1.blue) color = Color.new(color_r, color_g, color_b) fill_rect(x, i, width, 1, color) end end end end
class Bitmap
def gradient_fill_rect(*args)
case args[0].size
when 7
x, y, width, height, color1, color2, vertical = args[0]
when 6
x, y, width, height, color1, color2, vertical = args[0] + [false]
when 4
rect, color1, color2, vertical = args[0]
when 3
rect, color1, color2 = args[0] + [false]
end
if rect != nil
x, y, width, height = rect.x, rect.y, rect.width, rect.height
end
if !vertical
for i in x..x+width
color_r = ((color1.red-color2.red)*(i-x).to_f/width + color1.red)
color_g = ((color1.green-color2.green)*(i-x).to_f/width + color1.green)
color_b = ((color1.blue-color2.blue)*(i-x).to_f/width + color1.blue)
color = Color.new(color_r, color_g, color_b)
fill_rect(i, y, 1, height, color)
end
else
for i in y..y+height
color_r = ((color1.red-color2.red)*(i-y).to_f/height + color1.red)
color_g = ((color1.green-color2.green)*(i-y).to_f/height + color1.green)
color_b = ((color1.blue-color2.blue)*(i-y).to_f/height + color1.blue)
color = Color.new(color_r, color_g, color_b)
fill_rect(x, i, width, 1, color)
end
end
end
end
效果自己测试一下就知道了
还请大神们看看啊 |
评分
-
查看全部评分
|