def setup
c = createCanvas(100, 100)
background(200)
textAlign(CENTER)
text('drop file', width / 2, height / 2)
c.drop do |file|
file = Native(`file`)
background(200)
text('dropped file:', width / 2, height / 2)
text(file.name, width / 2, height / 2 + 40) # ファイル名を表示
end
end
def setup
c = createCanvas(100, 100)
background(200)
textAlign(CENTER)
text('drop image', width / 2, height / 2)
c.drop do |file|
file = Native(`file`)
@img = createImg(file.data, '').hide # <img>要素を生成
end
end
def draw
if (@img)
image(@img, 0, 0, width, height) # <img>要素を描画
end
end
ファイルが要素上にドロップされたときに実行する処理を登録します。
| 引数名 | 内容 | 備考 | オプション | デフォルト値 |
|---|---|---|---|---|
| ... | ブロック | 実行する処理 |
なし
・ブロック引数として fileオブジェクトを受け取りますが、
rbCanvas/p5上でこのオブジェクトを扱うためには Nativeメソッドでの変換が必要です。