简单的HSL渐变
边学边练RUBY 代码
下) 无符号整型
# color 椭圆边框颜色 RMXP的Color实例对象
# fillB 椭圆填充的起始颜色 RMXP的Color实例对象
# fillE 椭圆填充的终止颜色 RMXP的Color实例对象 或 nil(单色填充)
#--------------------------------------------------------------------
def fill_ellipse3(cx, cy, ax, by, mode, color, fillB, fillE=nil)
if fillE
if mode == 0
step = ax + ax + 1
src_rect = Rect.new(0, 0, 0, 0)
else
step = by + by + 1
end
src = Bitmap.new(step, 1)
DrawScanH.call(src.object_id, fillB.object_id, fillE.object_id)
else
mode = 1if mode = 0
end
ratio, w2 = ax.to_f / by,0
(by).downto(1)do |y|
w = (Math.sqrt((by + y) * (by - y)) * ratio).round
if fillE
if mode == 1
self.fill_rect(cx - w, cy - y, w + w, 1, src.get_pixel(by - y, 0))
self.fill_rect(cx - w, cy + y, w + w, 1, src.get_pixel(by + y, 0))
else
src_rect.set(ax - w, 0, w + w, 1)
self.blt(cx - w, cy - y, src, src_rect)
self.blt(cx - w, cy + y, src, src_rect)
end
else
self.fill_rect(cx - w, cy - y, w + w, 1, fillB)
self.fill_rect(cx - w, cy + y, w + w, 1, fillB)
end
self.set_pixel(cx - w, cy - y, color)
self.set_pixel(cx + w, cy - y, color)
self.set_pixel(cx - w, cy + y, color)
self.set_pixel(cx + w, cy + y, color)
while w2 < w
self.set_pixel(cx - w2, cy - y - 1, color)
self.set_pixel(cx + w2, cy - y - 1, color)
self.set_pixel(cx - w2, cy + y + 1, color)
self.set_pixel(cx + w2, cy + y + 1, color)
w2 += 1
end
end
if fillE
if mode == 1
self.fill_rect(cx - ax, cy, ax + ax + 1, 1, src.get_pixel(by, 0))
else
self.blt(cx - ax, cy, src, src.rect)
end
else
self.fill_rect(cx - ax, cy, ax + ax + 1, 1, fillB)
end
self.set_pixel(cx - ax, cy, color)
self.set_pixel(cx + ax, cy, color)
src.disposeif src
end
def draw_text_ex(x, y, text, color0, color1)
rect = self.text_size(text)
temp = Bitmap.new(rect.width, rect.height)
temp.draw_text(rect, text)
FillTextH.call(temp.object_id, color0.object_id, color1.object_id)
self.blt(x, y, temp, rect)
temp.dispose
end
end
本帖来自P1论坛作者RPGzh500223,因Project1站服务器在国外有时候访问缓慢不方便作者交流学习,经联系P1站长fux2同意署名转载一起分享游戏制作经验,共同为国内独立游戏作者共同创造良好交流环境,原文地址:https://rpg.blue/forum.php?mod=viewthread&tid=488994若有侵权,发帖作者可联系底部站长QQ在线咨询功能删除,谢谢。
页:
[1]