2 # StrokeFont library by eto 2003-0311
9 class StrokesRenderer #======================================================================
17 def init() @start_time = Time.now; end
18 def set_strokes(strokes)
23 return if @strokes.nil?
24 @strokes.strokes.each_with_index {|stroke, index|
25 #draw_delay(stroke, index)
26 draw_alpha(stroke, 100)
29 def draw_alpha(stroke, time)
33 stroke.points.each {|x, y|
35 colorHSV(@hsv[0], @hsv[1], @hsv[2], a*100.0)
36 line(px, py, x, y) if (px != 0 || py != 0) #最初の点ではない
41 def draw_delay(stroke, index)
43 @start_time = Time.now if @start_time == nil
44 diff = now - @start_time #開始からの秒数がはいる
45 draw_alpha(stroke, diff - index*0.3)
49 class Stroke #====================================================================== 一本の線
59 return @length if @length
64 len += Math.sqrt((x-px)*(x-px)+(y-py)*(y-py))
73 class Strokes #====================================================================== 複数の線
76 @px1, @py1, @px2, @py2 = 0, 0, 0, 0
77 @x1, @y1, @x2, @y2 = 0, 0, 0, 0
81 def add_line(x1, y1, x2, y2)
82 if (@px != x1 || @py != y1) #以前の点とつながっていなかったら、
83 @strokes << Stroke.new
84 @strokes.last.add_point(x1, y1)
86 @strokes.last.add_point(x2, y2)
92 #----------------------------------------------------------------------end.