ofruby 0.2 リリース - タッチ入力が取得出来るようになりました

ofruby 0.2 をリリースしました。

新機能

width, heightでウィンドウのサイズを取得出来るようになったり、Input.touch(idx), Input.touchesでマルチタッチ入力を取得出来るようになりました。set_background_autoをfalseに設定すると毎Fフレームバッファをクリアせずに加算表示されるようになります。(Processingのデフォルト)

  • width, height
  • Input.touch(idx), Input.touches
  • TouchPoint#valid?, x, y, press?, down?, release?
  • set_background_auto
  • set_circle_resolution
  • Rename from get_frame_rate to frame_rate

ダウンロードはこちらからどうぞ。

タッチ入力のサンプル

画面にタッチした押した場所にボールを落とします。RubyのArray#find_allを使うことでとても簡単にマルチタッチにも対応出来ました。


def setup
  @balls = []
  @prev = false
end

def update
  ta = Input.touches.find_all { |e| e.release? }
  ta.each do |t|
    @balls.push Ball.new t.x, t.y, 0
  end
  @balls.each { |v| v.update }
end

def draw
  set_color_hex 0
  #text "#{Input.touch(0).x}", 0, 100
  @balls.each { |v| v.draw }
  set_color_hex 0x864040
  rect_rounded 0, 420, 320,20, 10
end

class Ball
  def initialize(x, y, init_speed)
    @x = x
    @y = y
    @accel = 0.098
    @speed = init_speed
    @color = rand(0xffffff)
  end

  def update
    @speed += @accel
    @y += @speed
    if @y > 410
      @y = 410
      @speed *= -0.8
    end
  end

  def draw
    #set_color_hex 0xd73a45
    set_color_hex @color
    set_fill
    circle @x, @y, 10
  end
end

0.3

AppStoreには申請済みです。次はnoise関数やMath.sinが使えるようになります。

RubyKaigi 2014

RubyKaigi 2014 | Lightning Talks で ofruby のことをしゃべります。ofrubyが動く実機(ただのiPod Touch)も持っていきますので興味のある人は@ongaeshiに声をかけて下さい。

Links