# ▼▲▼ XRXL 1. ライン・図形描写 ▼▲▼ # by 桜雅 在土, 和希 #============================================================================== # ◇ 外部ライブラリ #============================================================================== class Bitmap #-------------------------------------------------------------------------- # ● ライン描画 軽量版 by 桜雅 在土 #-------------------------------------------------------------------------- def draw_lineght(start_x, start_y, end_x, end_y, start_color) # 描写距離の計算。大きめに直角時の長さ。 distance = (start_x - end_x).abs + (start_y - end_y).abs # 描写開始 for i in 1..distance x = (start_x + 1.0 * (end_x - start_x) * i / distance).to_i y = (start_y + 1.0 * (end_y - start_y) * i / distance).to_i self.set_pixel(x, y, start_color) end end #-------------------------------------------------------------------------- # ● ライン描画 by 桜雅 在土 #-------------------------------------------------------------------------- def draw_line(start_x, start_y, end_x, end_y, start_color, width = 1, end_color = start_color) # 描写距離の計算。大きめに直角時の長さ。 distance = (start_x - end_x).abs + (start_y - end_y).abs # 描写開始 if end_color == start_color for i in 1..distance x = (start_x + 1.0 * (end_x - start_x) * i / distance).to_i y = (start_y + 1.0 * (end_y - start_y) * i / distance).to_i if width == 1 self.set_pixel(x, y, start_color) else self.fill_rect(x, y, width, width, start_color) end end else for i in 1..distance x = (start_x + 1.0 * (end_x - start_x) * i / distance).to_i y = (start_y + 1.0 * (end_y - start_y) * i / distance).to_i r = start_color.red * (distance-i)/distance + end_color.red * i/distance g = start_color.green * (distance-i)/distance + end_color.green * i/distance b = start_color.blue * (distance-i)/distance + end_color.blue * i/distance a = start_color.alpha * (distance-i)/distance + end_color.alpha * i/distance if width == 1 self.set_pixel(x, y, Color.new(r, g, b, a)) else self.fill_rect(x, y, width, width, Color.new(r, g, b, a)) end end end end #-------------------------------------------------------------------------- # ● 等辺多角形の描画(塗りつぶしなし) by 和希 # center_x : 中心位置X # center_y : 中心位置Y # r : 外接円の半径 # n : 頂点の数(360とかにすると疑似円になります) # color : 線の色 # width : 線の幅 #-------------------------------------------------------------------------- def draw_eq_polygon(center_x, center_y, r, n, color, width = 1) d = Math::PI * 2.0 / n # 辺(=頂点)の個数分だけ辺を描く for i in 0 ... n # 現在の頂点の座標 x1 = center_x + r * Math.sin( d * i ) y1 = center_y - r * Math.cos( d * i ) # 次の頂点の座標 x2 = center_x + r * Math.sin( d * (i+1) ) y2 = center_y - r * Math.cos( d * (i+1) ) # 頂点同士を線で結ぶ draw_line( x1.abs, y1.abs, x2.abs, y2.abs, color, width ) end end #-------------------------------------------------------------------------- # ● Rectの描画(draw_polygonを利用) #-------------------------------------------------------------------------- def draw_rect(rect, color = Color.new(255, 255, 255, 255)) self.draw_polygon([ [rect.x , rect.y ], [rect.x + rect.width, rect.y ], [rect.x + rect.width, rect.y + rect.height], [rect.x , rect.y + rect.height] ], color, 1) end #-------------------------------------------------------------------------- # ● 多角形の描画(塗りつぶしなし) by 和希 # peaks : 頂点座標の配列 [[x1,y1],[x2,y2],[x3,y3], ... ] # color : 線の色 # width : 線の幅 #-------------------------------------------------------------------------- def draw_polygon(peaks, color, width = 1) # 辺(=頂点)の個数分だけ辺を描く for i in 0 ... (peaks.size - 1) # 頂点同士を線で結ぶ draw_line( peaks[i][0], peaks[i][1], peaks[i+1][0], peaks[i+1][1], color, width ) end # 最後の頂点と最初の頂点を結ぶ draw_line( peaks[peaks.size - 1][0], peaks[peaks.size - 1][1], peaks[0][0], peaks[0][1], color, width ) end #-------------------------------------------------------------------------- # ● 楕円の描画(塗りつぶしなし) by 和希 # center_x : 中心位置X # center_y : 中心位置Y # rx : 縦の半径 # ry : 横の半径 # color : 線の色 # width : 線の幅 #-------------------------------------------------------------------------- def draw_ellipse(center_x, center_y, rx, ry, color, width = 1) d = Math::PI * 2.0 / 360 # 360角形を描いて円っぽく見せる for i in 0 ... 360 # 現在の頂点の座標 x1 = center_x + rx * Math.sin( d * i ) y1 = center_y - ry * Math.cos( d * i ) # 次の頂点の座標 x2 = center_x + rx * Math.sin( d * (i+1) ) y2 = center_y - ry * Math.cos( d * (i+1) ) # 頂点同士を線で結ぶ draw_line( x1.abs, y1.abs, x2.abs, y2.abs, color, width ) end end end # ▼▲▼ XRXL 2. ビットマップ/アイコン描写 ▼▲▼ # by 桜雅 在土 #============================================================================== # ◇ 外部ライブラリ #============================================================================== class Bitmap #-------------------------------------------------------------------------- # ● バトラーの顔&枠の描画 # battler : バトラー # x : 描画先 X 座標 # y : 描画先 Y 座標 #-------------------------------------------------------------------------- def draw_battler_facesquare(battler, x, y, size = 24) if battler.is_a?(Game_Actor) character_name = battler.character_name character_hue = battler.character_hue elsif battler.is_a?(Game_Enemy) character_name = battler.battler_name character_hue = battler.battler_hue else return end draw_facesquare(character_name, character_hue, x, y, size) end #-------------------------------------------------------------------------- # ● 顔&枠の描画 # character_name : 描写に利用するキャラクターグラフィック # character_hue : 描写の色合い # x : 描画先 X 座標 # y : 描画先 Y 座標 #-------------------------------------------------------------------------- def draw_facesquare(character_name, character_hue, x, y, size = 24) bitmap = RPG::Cache.character(character_name, character_hue) src_rect = Rect.new((bitmap.width/4 - size)/2, 0, size, size) self.blt(x, y, bitmap, src_rect) self.draw_polygon([[x,y],[x+size,y],[x+size,y+size],[x,y+size]], Color.new(255,255,255,128)) end end