# anim.rb # Example of Ming for Ruby # http://opaque.net/ming/examples/animation.html require 'ming/ming' include Ming ARGV[0] = 'ming!' if ARGV.empty? @f = SWFFont.new('courier_new.fdb') @m = SWFMovie.new @m.set_rate(24.0) @m.set_dimension(320, 240) @m.set_background(0xff, 0xff, 0xff) class SWFDisplayItem attr_accessor :x, :y, :rot, :s end def text(r, g, b, a, rot, x, y, scale, string) t = SWFText.new t.set_font(@f) t.set_color(r, g, b, a) t.set_height(96) t.move_to(- t.get_width(string)/2, 32) t.add_string(string) i = @m.add(t) i.x = x i.y = y i.rot = rot i.s = scale i.rotate_to(rot) i.scale(scale, scale) i end def step(i) @oldrot = i.rot rot = 19 * i.rot / 20 i.x = (19 * i.x + 160)/20 i.y = (19 * i.y + 120)/20 i.s = (19 * i.s + 1.0)/20 i.rotate_to(i.rot) i.scale_to(i.s, i.s) i.move_to(i.x, i.y) i end array = [] [ [0xff, 0x33, 0x33, 0xff, 900, 160, 120, 0.03, ARGV[0]], [0x00, 0x33, 0xff, 0x7f, -560, 160, 120, 0.04, ARGV[0]], [0xff, 0xff, 0xff, 0x9f, 180, 160, 120, 0.001, ARGV[0]], ].each do |r, g, b, a, rot, x, y, scale, string| array.push (text(r, g, b, a, rot, x, y, scale, string)) end 100.times do |i| 3.times do |j| array[j] = step(array[j]) @m.next_frame end end @m.save('anim.swf')