動作確認
Windows 7 pro
openprocessingというブラウザ動作の環境でProcessingを試した。
int counter;
void setup() { //setup function called initially, only once
size(250, 250);
background(255); //set background white
colorMode(HSB); //set colors to Hue, Saturation, Brightness mode
counter = 0;
}
void draw() { //draw function loops
counter++;
// noStroke();
stx = random(50);
sty = random(50);
wid = random(100);
hei = random(100);
line( stx, sty, stx+wid, sty+hei);
if(mousePressed == true) { //add some interaction
noStroke();
}
}
マウスクリックした時点で線の追加をやめる実装。
最初から動かしなおす場合は、ブラウザのリロードを使う。
C++ Builder, Visual Studio, Unity以外の描画ツールとして使えるだろうか。。。
v0.2 > クリック時にクリア
参考 https://forum.processing.org/one/topic/how-to-clear-the-screen-after-drawing-something.html
just call background(yourBgColor);
background()で描画したものを消すらしい。
void setup() { //setup function called initially, only once
size(250, 250);
background(255); //set background white
colorMode(HSB); //set colors to Hue, Saturation, Brightness mode
counter = 0;
}
void draw() { //draw function loops
counter++;
// noStroke();
stx = random(50);
sty = random(50);
wid = random(100);
hei = random(100);
line( stx, sty, stx+wid, sty+hei);
if(mousePressed == true) { //add some interaction
background(255);
}
}
(追記 2016/07/13)
Windows用Processing3で実行する場合は上記コードではエラーが出て、以下のように変更が必要だった。
変数の型宣言を明示しないといけないとのこと。
また、random()の戻り値がfloatのためエラーが出た。(int)で対応した。
int counter;
void setup() { //setup function called initially, only once
size(250, 250);
background(255); //set background white
colorMode(HSB); //set colors to Hue, Saturation, Brightness mode
counter = 0;
}
void draw() { //draw function loops
counter++;
// noStroke();
int stx, sty, wid, hei;
stx = (int)random(50);
sty = (int)random(50);
wid = (int)random(100);
hei = (int)random(100);
line( stx, sty, stx+wid, sty+hei);
if(mousePressed == true) { //add some interaction
background(255);
}
}