実践1:連番画像を作成する

今まで作った、クラスを使って、
(少し)実用的なプログラムを作ってみた。
実行すると、カレントディレクトリ内の
「images」ディレクトリ内に、画像を自動作成します。

後は、これをなんらかのツールで動画にするのだが、
いっそのこと、JMFでもつかって、一気に動画にしてもよいね。
今後の課題ということで・・・(^^;)

import ryugate.image._
import ryugate.video._
import ryugate.text.Format

import java.io.File

import java.awt.Font
import java.awt.Color
import java.awt.image.BufferedImage

object make_sequence extends Application {
  val rate = 15
  val second = 60

  def make_frame(no:int):Unit = no match {
    case -1 => no
    case _ => {
      val filename = Format.sprintf("images/%04d.jpg", no)
      println(filename)

      val img = new Image(400,300, BufferedImage.TYPE_INT_RGB)
      img.clearBackground(Color.BLUE)
      img.process {
          g.drawString(new Timecode(no).tc(rate).toString, 50,100)
          g.drawString(Format.sprintf("%04d", no), 50,150)
        })
      })
      img.write("jpg", new File(filename">*1

      make_frame(no-1)
    }
  }

  make_frame(rate*second)  
}

*1:g) => { g.setFont("MS Gothic", Font.BOLD, 48) g.antialias((g) => { g.drawString(new Timecode(no).tc(rate).toString, 50,100) g.drawString(Format.sprintf("%04d", no), 50,150) }) }) img.write("jpg", new File(filename