# $Id: illumtext.rb,v 1.3 2003/10/23 06:44:32 knok Exp $

require 'color'
require 'ming/ming'
require 'mingtext'
include Ming

class IllumText
  attr_reader :texts, :textlen
  @@divo = 4
  @@starttime = 10
  def initialize(movie, dim, num)
    @texts = []
    @movie = movie
    @num = num
    @offsets = []
    @dx = dim[0] / 2
    @dy = dim[1] / 2
    @textlen = 0
    @curtime = @@starttime
    (num - 1).downto(0) do |n|
      @offsets.push(@@divo * n)
    end
  end
  def setrightuptext(str, tsize, font, color)
    @offsets.each do |o|
      ary = gentp(@@starttime + o)
      swft = rightuptext(str, tsize, font, color)
      @textlen = swft.get_width(str)
      text = @movie.add(swft)
      text.rotate_to(ary[0])
      text.scale_to(ary[1])
      text.add_color(-ary[2], -ary[2], -ary[2])
      text.move_to(@dx + @textlen / 2, @dy)
      @texts.push(text)
    end
  end
  def setoffsetloc(x, y)
    @dx = x
    @dy = y
    @texts.each do |text|
      text.move_to(@dx, @dy)
    end
  end
  def iteration()
    @curtime = @curtime - 1
    if (@curtime < -20)
      @curtime = -20
      return
    end
    0.upto(@num-1) do |a|
      text = @texts[a]
      ary = gentp(@curtime + @offsets[a])
      text.rotate_to(ary[0])
      text.scale_to(ary[1])
      text.add_color(-ary[2], -ary[2], -ary[2])
    end
  end
  def gentp(i)
    # angle, ratio, colordelta
    if (i < 0)
      return [0, 1, 0]
    end
    return [i * 2, 1 + i.to_f/50, i * 8]
  end
end
