Processing/2.ちょっと発展/1.アクティブなスケッチ
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
|
ログイン
]
開始行:
* 2-1 アクティブなスケッチ [#b4b938c2]
次のスケッチでは、最初にvoid setup()に続く{ }内のコード...
void setup(){
size(400,400);
}
void draw(){
circle(mouseX, mouseY, 20);
}
このスケッチではマウスのポインタの位置(mouseX, mouseY)に...
void setup(){
size(400,400);
}
void draw(){
background(64);
circle(mouseX, mouseY, 20);
}
これで、ポインタの位置に〇が描かれることがわかる。
このように、drawの最初に画面を消去することで、〇が動いて...
background()で背景を塗りつぶす代わりに、rect(0,0,width,he...
【プログラム A】
void setup(){
size(400,400);
}
void draw(){
fill(0);
rect(0,0,width,height);
fill(255);
circle(mouseX, mouseY, 20);
}
今度はマウスを追いかけるのではなく、〇を左から右へ動かし...
float x, y;
void setup(){
size(400,400);
x = 0;
y = height / 2;
}
void draw(){
background(64);
circle(x, y, 20);
x = x + 2;
}
このままだと、右端まで行くと〇は戻ってこない。そこで、端...
if(条件){ 条件が真のときに実行するコード } else { 条件が...
例えば、
if( x<0 ) { dx = 2; }
は、変数xの値が負であれば、dxに2を代入し、そうでなければ...
float x, y, dx;
void setup(){
size(400,400);
x = 0;
y = height / 2;
dx = 2;
}
void draw(){
background(64);
circle(x, y, 20);
if( x < 0 ) { dx = 2; }
if( x > width ) { dx = -2; }
x = x + dx;
}
条件には、等式または不等式を記す。等号は=を2つ並べること...
【プログラム B】
float x, y, dx;
void setup(){
size(400,400);
x = 0;
y = height / 2;
dx = 2;
}
void draw(){
background(64);
circle(x, y, 20);
if( x < 0 || x > width ) { dx = -dx; }
x = x + dx;
}
何も指定しなければ、void draw(){}は1秒に60回実行される。...
float x, y, dx;
void setup(){
size(400,400);
x = 0;
y = height / 2;
dx = 2;
frameRate(20);
}
void draw(){
background(64);
circle(x, y, 20);
if( x < 0 || x > width ) { dx = -dx; }
x = x + dx;
}
【課題】
プログラムAで、試しにfill(0)をfill(0,10)に変えてみよう。...
プログラムBを変更して、斜めに動くようにせよ。上下端で反射...
終了行:
* 2-1 アクティブなスケッチ [#b4b938c2]
次のスケッチでは、最初にvoid setup()に続く{ }内のコード...
void setup(){
size(400,400);
}
void draw(){
circle(mouseX, mouseY, 20);
}
このスケッチではマウスのポインタの位置(mouseX, mouseY)に...
void setup(){
size(400,400);
}
void draw(){
background(64);
circle(mouseX, mouseY, 20);
}
これで、ポインタの位置に〇が描かれることがわかる。
このように、drawの最初に画面を消去することで、〇が動いて...
background()で背景を塗りつぶす代わりに、rect(0,0,width,he...
【プログラム A】
void setup(){
size(400,400);
}
void draw(){
fill(0);
rect(0,0,width,height);
fill(255);
circle(mouseX, mouseY, 20);
}
今度はマウスを追いかけるのではなく、〇を左から右へ動かし...
float x, y;
void setup(){
size(400,400);
x = 0;
y = height / 2;
}
void draw(){
background(64);
circle(x, y, 20);
x = x + 2;
}
このままだと、右端まで行くと〇は戻ってこない。そこで、端...
if(条件){ 条件が真のときに実行するコード } else { 条件が...
例えば、
if( x<0 ) { dx = 2; }
は、変数xの値が負であれば、dxに2を代入し、そうでなければ...
float x, y, dx;
void setup(){
size(400,400);
x = 0;
y = height / 2;
dx = 2;
}
void draw(){
background(64);
circle(x, y, 20);
if( x < 0 ) { dx = 2; }
if( x > width ) { dx = -2; }
x = x + dx;
}
条件には、等式または不等式を記す。等号は=を2つ並べること...
【プログラム B】
float x, y, dx;
void setup(){
size(400,400);
x = 0;
y = height / 2;
dx = 2;
}
void draw(){
background(64);
circle(x, y, 20);
if( x < 0 || x > width ) { dx = -dx; }
x = x + dx;
}
何も指定しなければ、void draw(){}は1秒に60回実行される。...
float x, y, dx;
void setup(){
size(400,400);
x = 0;
y = height / 2;
dx = 2;
frameRate(20);
}
void draw(){
background(64);
circle(x, y, 20);
if( x < 0 || x > width ) { dx = -dx; }
x = x + dx;
}
【課題】
プログラムAで、試しにfill(0)をfill(0,10)に変えてみよう。...
プログラムBを変更して、斜めに動くようにせよ。上下端で反射...
ページ名: