ruby-processingでpresentation-tool作成、テストコードその1

 processingでテキストを表示するためのAPIを使ったら、簡単にプレゼンテーションツールが出来るのでは?
っと思ったので試してみた。


 で、実装してみたが、結構簡単に出来た。
まあ、まだ

  • フルスクリーン
  • 画面外に出た文字の自動折り返し
  • アニメーション

等が未対応で実装しなくてはならないです。*1


しかし完成してもプログラム臭くて、一般の人は絶対使わないだろうけどw;

require 'kconv'
require 'pp'

class TextControl
  def initialize
    @font = create_font "MS Gothic", 40
    @count = 0
    
    @pages = [
    { :text => %w[ ruby-processing ],
      :size => 60,
      :comment => "",
    },
    { :text => %w[ ・基本コマンド ・2D ・3D ],
    },
    { :text => %w[ rp5_create rp5_run rp5_watch ],
      :size => 24,
      :comment => "アンダーバーは、スペースと置換してね^^",
    },
    ]
  end
  
  def update page
    push_matrix
    translate width/5,height/4
    
    fill 255
    page = @pages[@count]

    begin
      text_font @font,(page[:size] ? page[:size] : 40)
      page[:text].each_with_index{|txt,j|
        text txt.toutf8,0,j*(page[:size] ? page[:size] : 40)*1.2
      }
    rescue => e
      text "404 not found".toutf8,0,40
    end

    pop_matrix
  end
  
  def key_pressed
    case key
    when 'n'#next
      @count += 1 if @count < @pages.length-1
    when 'p'#back
      @count -= 1 if 0 < @count
    when 'c'#return start_page
      @count = 0
    else
    end
    puts @count
  end
end

def setup
  size 640,400
  frame_rate 5
  smooth

  @text = TextControl.new
  @page = 0
end

def draw
  background 0
  
  @text.update(@page)
end

def key_pressed
  @text.key_pressed
end

*1:でも、以下でも高橋メソッド程度なら十分だし