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.
13 $LOAD_PATH << '../../src' if $0 == __FILE__
18 class StrokesRenderer #======================================================================
22 # @hsv = [0, 0, 100] #白
27 def init() @start_time = Time.now; end
28 def set_strokes(strokes)
33 return if @strokes.nil?
34 @strokes.strokes.each_with_index {|stroke, index|
35 #draw_delay(stroke, index)
36 draw_alpha(stroke, 100)
39 def draw_alpha(stroke, time)
43 stroke.points.each {|x, y|
45 colorHSV(@hsv[0], @hsv[1], @hsv[2], a*100.0)
46 line(px, py, x, y) if (px != 0 || py != 0) #最初の点ではない
51 def draw_delay(stroke, index)
53 @start_time = Time.now if @start_time == nil
54 diff = now - @start_time #開始からの秒数がはいる
55 draw_alpha(stroke, diff - index*0.3)
59 class Stroke #====================================================================== 一本の線
69 return @length if @length
74 len += Math.sqrt((x-px)*(x-px)+(y-py)*(y-py))
83 class Strokes #====================================================================== 複数の線
86 @px1, @py1, @px2, @py2 = 0, 0, 0, 0
87 @x1, @y1, @x2, @y2 = 0, 0, 0, 0
91 def add_line(x1, y1, x2, y2)
92 if (@px != x1 || @py != y1) #以前の点とつながっていなかったら、
93 @strokes << Stroke.new
94 @strokes.last.add_point(x1, y1)
96 @strokes.last.add_point(x2, y2)
102 #----------------------------------------------------------------------end.