赞 | 1 |
VIP | 246 |
好人卡 | 87 |
积分 | 1 |
经验 | 34142 |
最后登录 | 2015-1-15 |
在线时间 | 323 小时 |
Lv1.梦旅人
- 梦石
- 0
- 星屑
- 55
- 在线时间
- 323 小时
- 注册时间
- 2010-8-21
- 帖子
- 666
|
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
本帖最后由 沙漠点灰 于 2011-4-17 15:11 编辑
某系统的附加产物:效果
提供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
复制代码 |
|