Processingで画像の上に文字やら塗りやら
前回の『Processingで映像テスト』のスケッチを使って、色々試してみた
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import processing.video.*; | |
Capture cam; | |
boolean onoff = true; | |
PVector camSize; | |
void setup(){ | |
size(400 ,300); | |
camSize = new PVector(320,240); | |
cam = new Capture(this, int(camSize.x),int(camSize.y)); | |
cam.start(); | |
} | |
void draw(){ | |
//画像を左右反転して表示する | |
//反転して、位置移動して表示、反転解除 | |
scale(-1,1); | |
image(cam,-camSize.x,0); | |
scale(-1,1); | |
//キーボード押すと画面の色変える | |
//※マウスの位置に連動 | |
if(onoff==false){ | |
tint(mouseY,mouseX,mouseX); //tint(R,G,B,alpha) | |
text(str(mouseX)+" , "+str(mouseY),10,10); //文字表示 | |
} | |
else{ | |
tint(255,255,255); | |
} | |
} | |
void captureEvent(Capture cam){ | |
cam.read(); | |
} | |
void keyPressed(){ | |
onoff =! onoff; | |
} |
内容は
・カメラから映像取得して表示(反転表示=鏡)
・キーボードを一度押すと「塗り」エフェクト適用
・マウスの位置で色がリアルタイムに変動
・キーボードをもう一度押すとエフェクト解除
実行結果
text() で文字表示
int() でfloatをintに変換
str() で数値を文字列に型変換
+ を使って文字列を結合
scale() で画像を反転
tint() で塗りつぶし
以上。
まだまだ基礎から
0 コメント:
コメントを投稿