#!ruby -Ks # -*- mode: ruby; encoding: sjis -*- # Last updated: <2015/03/22 01:03:24 +0900> # # GIMP 1.x の「RGB交換」と似た感じでアニメーションしてみるテスト # # Ruby 1.9.3 + DXRuby 1.4.1 require 'dxruby' SS_SAVE = false FPS_V = 60 ANG_SPD = 360.0 / FPS_V V_SPD = 255.0 / FPS_V R_SPD_A = 2.0 / FPS_V R_SPD_B = 20.0 / FPS_V imgs = [] ["r.png", "g.png", "b.png"].each do |fn| imgs.push(Image.load(fn)) end Window.fps = FPS_V Window.resize(640, 480) rt = RenderTarget.new(Window.width, Window.height) step = 0 ang = 0 v = 0 r = Window.width / 2 r_spd = 0 timer = 0 framecount = 0 Window.loop do break if Input.keyPush?(K_ESCAPE) case step when 0 ang += ANG_SPD v += V_SPD v = 255 if v > 255 r -= r * R_SPD_A if r <= 1 v = 255 r = 0 step += 1 timer = FPS_V * 3 / 4 end when 1 timer -= 1 step += 1 if timer <= 0 when 2 ang += ANG_SPD v -= V_SPD v = 0 if v < 0 r += r_spd r_spd += R_SPD_B if r >= Window.width / 2 v = 0 r_spd = 0 timer = FPS_V / 2 step += 1 end when 3 timer -= 1 if timer <= 0 if SS_SAVE break else step = 0 end end end a = ang imgs.each do |img| x = r * Math.cos(a * Math::PI / 180.0) + Window.width / 3 y = r * Math.sin(a * Math::PI / 180.0) + Window.height / 2 rt.draw_ex(x, y, img, :offset_sync => true, :blend => :add, :alpha => v) a += 360 / 3 end Window.draw(0, 0, rt) if SS_SAVE oimg = rt.to_image fn = sprintf("ss_%04d.png", framecount) oimg.save(fn, FORMAT_PNG) end framecount += 1 end