3 # StrokeFont library by eto 2003-0311
4 # Copyright (C) 2002-2003 Kouichirou Eto
6 # This is free software with ABSOLUTELY NO WARRANTY.
8 # You can redistribute it and/or modify it under the terms of
9 # the GNU General Public License version 2.
17 class StrokesRenderer #======================================================================
25 def init() @start_time = Time.now; end
26 def set_strokes(strokes)
31 return if @strokes.nil?
32 @strokes.strokes.each_with_index {|stroke, index|
33 #draw_delay(stroke, index)
34 draw_alpha(stroke, 100)
37 def draw_alpha(stroke, time)
41 stroke.points.each {|x, y|
43 colorHSV(@hsv[0], @hsv[1], @hsv[2], a*100.0)
44 line(px, py, x, y) if (px != 0 || py != 0) #最初の点ではない
49 def draw_delay(stroke, index)
51 @start_time = Time.now if @start_time == nil
52 diff = now - @start_time #開始からの秒数がはいる
53 draw_alpha(stroke, diff - index*0.3)
57 class Stroke #====================================================================== 一本の線
67 return @length if @length
72 len += Math.sqrt((x-px)*(x-px)+(y-py)*(y-py))
81 class Strokes #====================================================================== 複数の線
84 @px1, @py1, @px2, @py2 = 0, 0, 0, 0
85 @x1, @y1, @x2, @y2 = 0, 0, 0, 0
89 def add_line(x1, y1, x2, y2)
90 if (@px != x1 || @py != y1) #以前の点とつながっていなかったら、
91 @strokes << Stroke.new
92 @strokes.last.add_point(x1, y1)
94 @strokes.last.add_point(x2, y2)
100 #----------------------------------------------------------------------end.