Project1
标题:
ISA 文字渐变 Text Gradient
[打印本页]
作者:
沙漠点灰
时间:
2011-4-16 16:15
标题:
ISA 文字渐变 Text Gradient
本帖最后由 沙漠点灰 于 2011-4-17 15:11 编辑
某系统的附加产物:效果
未命名.jpg
(56.96 KB, 下载次数: 17)
下载附件
保存到相册
2011-4-16 16:14 上传
提供10种渐变,实质只有几种;图中最后个数字代表方式;
0.中央渐变
1~4 & 6~9参考小键盘位置
比如4就是左到右,9就是右上到左下,很好理解
5为中心辐射,效果和0差不多,但算法不一样(废话),5就像太阳,而0像调色板...嘛,反正差不多
使用方法
bitmap_obj.draw_text(x,y,width,height,str,对齐方式,[渐变方法,color1,color2])
或者:
bitmap_obj.draw_text(rect,str,对齐方式,[渐变方法,color1,color2])
注意,[渐变方法,color1,color2]是数组,[]不可省略,使用渐变必须把对齐方式填了...
这张截图使用脚本:
size = 58
devil = []
0.upto(9){|i|
devil << Sprite.new
devil[-1].bitmap = Bitmap.new(640,480)
devil[-1].bitmap.font.size = size
array = [i, Color.new(255,0,0), Color.new(255,255,255)]
if i == 0
x,y = 220,360
else
x,y = (i-1)%3 * 220,(9-i)/3*120
end
devil[-1].bitmap.draw_text(x,y,size*3.5,size,"66RPG_#{i}",0,array)}
loop do
Graphics.update
end
复制代码
脚本如下:
#______________________________________________________________________________
# * 此脚本归66RPG - Idiot Script Association(ISA)所有,谢绝任何形式转载。
#______________________________________________________________________________
#==============================================================================
# ■ 文字渐变 Text Gradient
#------------------------------------------------------------------------------
# 遵守协议:66RPG - Idiot Script Association(ISA)
# 当前版本:0.1.0.0
#------------------------------------------------------------------------------
# 更新日记:沙漠.灰(2011.4.16)
# - 初始化
#==============================================================================
#==============================================================================
# ■ Bitmap
#------------------------------------------------------------------------------
# 位图 类
#==============================================================================
class Bitmap
#--------------------------------------------------------------------------
# ● 描绘字符串
# arrar 格式 arrar = [where, color1, color2]
# where : 渐变起始位置 值为:4 5 6 2 8
# color1 : 起始颜色 Color类
# color2 : 结束颜色 Color类
#--------------------------------------------------------------------------
alias isa_draw_text draw_text unless Bitmap.method_defined? "isa_draw_text"
def draw_text(x, y="", width=0, height=[], str="", align=0,array=[])
if x.is_a? Rect
s1 = x.x
s2 = x.y
s3 = x.width
s4 = x.height
return draw_text(s1,s2,s3,s4,y,width,height)
end
isa_draw_text(x, y, width, height, str, align)
return if array == [] or !(0..9).to_a.include? array[0]
case array[0]
when 0 # 中心渐变
# 计算中心坐标
cen_x = x + width / 2
cen_y = y + height/ 2
# 计算每(左右)像素应增加RGB值
r_p_46 = (array[2].red - array[1].red ) /width
g_p_46 = (array[2].green- array[1].green) /width
b_p_46 = (array[2].blue - array[1].blue ) /width
# 计算每(上下)像素应增加RGB值
r_p_28 = (array[2].red - array[1].red ) /height
g_p_28 = (array[2].green- array[1].green) /height
b_p_28 = (array[2].blue - array[1].blue ) /height
# 循环位图(坐标,我也不知道从哪开始)
for n_x in x...x+width
for n_y in y...y+height
alpha = self.get_pixel(n_x, n_y).alpha
next if alpha == 0
r_new = array[1].red + (r_p_46 * (n_x - cen_x).abs+r_p_28 * (n_y - cen_y).abs)/2
g_new = array[1].green + (g_p_46 * (n_x - cen_x).abs+g_p_28 * (n_y - cen_y).abs)/2
b_new = array[1].blue + (b_p_46 * (n_x - cen_x).abs+b_p_28 * (n_y - cen_y).abs)/2
self.set_pixel(n_x, n_y,Color.new(r_new, g_new, b_new, alpha))
end
end
when 1 # 右上渐变
# 调用 9 翻转
temp = [9, array[2], array[1], array[3]]
return draw_text(x, y, width, height, str, align, temp)
when 2 # 从下至上
# 调用 8 翻转
temp = [8, array[2], array[1], array[3]]
return draw_text(x, y, width, height, str, align, temp)
when 3 # 左上渐变
# 调用 7 翻转
temp = [7, array[2], array[1], array[3]]
return draw_text(x, y, width, height, str, align, temp)
when 4 # 从左至右
# 计算每像素应增加RGB值
r_p = (array[2].red - array[1].red ) / width
g_p = (array[2].green- array[1].green) / width
b_p = (array[2].blue - array[1].blue ) / width
# 循环位图(坐标,左开始)
for n_x in x...x+width
for n_y in y...y+height
alpha = self.get_pixel(n_x, n_y).alpha
next if alpha == 0
r_new = array[1].red + r_p * (n_x - x)
g_new = array[1].green + g_p * (n_x - x)
b_new = array[1].blue + b_p * (n_x - x)
self.set_pixel(n_x, n_y,Color.new(r_new, g_new, b_new, alpha))
end
end
when 5 # 中心辐射
# 计算中心坐标
cen_x = x + width / 2
cen_y = y + height/ 2
# 计算每像素应增加RGB值
len = Math.sqrt(height**2 + width**2)
r_p = (array[2].red - array[1].red ) / len
g_p = (array[2].green- array[1].green) / len
b_p = (array[2].blue - array[1].blue ) / len
# 循环位图(坐标,我也不知道从哪开始)
for n_x in x...x+width
for n_y in y...y+height
alpha = self.get_pixel(n_x, n_y).alpha
next if alpha == 0
step = Math.sqrt((n_x - cen_x)**2 + (n_y - cen_y)**2)
r_new = array[1].red + r_p * step
g_new = array[1].green + g_p * step
b_new = array[1].blue + b_p * step
self.set_pixel(n_x, n_y,Color.new(r_new, g_new, b_new, alpha))
end
end
when 6 # 从右至左
# 调用 4 翻转
temp = [4, array[2], array[1], array[3]]
return draw_text(x, y, width, height, str, align, temp)
when 7 # 右下渐变
# 计算每(左右)像素应增加RGB值
r_p_46 = (array[2].red - array[1].red ) / width
g_p_46 = (array[2].green- array[1].green) / width
b_p_46 = (array[2].blue - array[1].blue ) / width
# 计算每(上下)像素应增加RGB值
r_p_28 = (array[2].red - array[1].red ) / height
g_p_28 = (array[2].green- array[1].green) / height
b_p_28 = (array[2].blue - array[1].blue ) / height
# 循环位图(坐标,我也不知道从哪开始)
for n_x in x...x+width
for n_y in y...y+height
alpha = self.get_pixel(n_x, n_y).alpha
next if alpha == 0
r_new = array[1].red + (r_p_46 * (n_x - x)+r_p_28 * (n_y - y))/2
g_new = array[1].green + (g_p_46 * (n_x - x)+g_p_28 * (n_y - y))/2
b_new = array[1].blue + (b_p_46 * (n_x - x)+b_p_28 * (n_y - y))/2
self.set_pixel(n_x, n_y,Color.new(r_new, g_new, b_new, alpha))
end
end
when 8 # 从上至下
# 计算每像素应增加RGB值
r_p = (array[2].red - array[1].red ) / height
g_p = (array[2].green- array[1].green) / height
b_p = (array[2].blue - array[1].blue ) / height
# 循环位图(坐标,上开始)
time= -1
for n_y in y...y+height
for n_x in x...x+width
alpha = self.get_pixel(n_x, n_y).alpha
next if alpha == 0
r_new = array[1].red + r_p * (n_y - y)
g_new = array[1].green + g_p * (n_y - y)
b_new = array[1].blue + b_p * (n_y - y)
self.set_pixel(n_x, n_y,Color.new(r_new, g_new, b_new, alpha))
end
end
when 9 # 左下渐变
# 计算每(左右)像素应增加RGB值
r_p_46 = (array[2].red - array[1].red ) / width
g_p_46 = (array[2].green- array[1].green) / width
b_p_46 = (array[2].blue - array[1].blue ) / width
# 计算每(上下)像素应增加RGB值
r_p_28 = (array[2].red - array[1].red ) / height
g_p_28 = (array[2].green- array[1].green) / height
b_p_28 = (array[2].blue - array[1].blue ) / height
# 循环位图(坐标,我也不知道从哪开始)
for n_x in (x...x+width).to_a.reverse
for n_y in y...y+height
alpha = self.get_pixel(n_x, n_y).alpha
next if alpha == 0
r_new = array[1].red + (r_p_46 * (x+width-n_x)+r_p_28 * (n_y - y))/2
g_new = array[1].green + (g_p_46 * (x+width-n_x)+g_p_28 * (n_y - y))/2
b_new = array[1].blue + (b_p_46 * (x+width-n_x)+b_p_28 * (n_y - y))/2
self.set_pixel(n_x, n_y,Color.new(r_new, g_new, b_new, alpha))
end
end
end
end
end
复制代码
作者:
小传子
时间:
2011-4-16 22:50
= =居然有人发布了,赶紧的看看先。
作者:
忧雪の伤
时间:
2011-6-19 15:58
本帖最后由 忧雪の伤 于 2011-6-19 16:01 编辑
size = 58
devil = []
0.upto(9){|i|
devil << Sprite.new
devil[-1].bitmap = Bitmap.new('Graphics/Titles/001-Title01')
devil[-1].bitmap.font.size = size
array = [i, Color.new(255,0,0), Color.new(255,255,255)]
if i == 0
x,y = 220,360
else
x,y = (i-1)%3 * 220,(9-i)/3*120
end
devil[-1].bitmap.draw_text(x,y,size*3.5,size,"66RPG_#{i}",0,array)}
loop do
Graphics.update
end
复制代码
试了这个就知道问题了。
这说明,依靠alpha来决定是否填充是不行的。
作者:
yangff
时间:
2011-6-19 17:44
set_pixel自重不解释,LZ可以试试遮罩= =或者挂个DLL啥的,再或者哟给你blt也好啊
欢迎光临 Project1 (https://rpg.blue/)
Powered by Discuz! X3.1