Processing/2.ちょっと発展/12.物理
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
|
ログイン
]
開始行:
#navi(Processing/2.ちょっと発展)
* 2-12. 物理 [#l4e9490a]
次のプログラムは〇をx方向に往復運動をするものだった。
float x, y, dx;
void setup(){
size(400,400);
x = 0;
y = height / 2;
dx = 2;
}
void draw(){
fill(0);
rect(0,0,width,height);
fill(255);
circle(x, y, 20);
if( x < 0 || x > width ) { dx = -dx; }
x = x + dx;
}
次のスケッチは、物理法則をそれなりに模擬する。
初速度20m/s、角度thで投げ上げられた物体の位置を計算し、そ...
Setupでは、thに投げ上げの角度を代入し、フレームレートをfp...
float x, y, vx, vy, dt;
void setup(){
size(800,300);
x = 0;
y = 0;
float th = 75;
vx = 20 * cos(radians(th));
vy = 20 * sin(radians(th));
float fps = 120;
frameRate(fps);
dt = 1.0 / fps;
}
void draw(){
fill(0);
rect(0, 0, width, height);
applyMatrix( 10, 0, 5, 0, -10, height-5 );
fill(255);
circle(x, y, 2);
x = x + vx * dt;
y = y + vy * dt;
vy = vy - 9.8 * dt;
}
物体が地面で弾性的に跳ね返るようにするには、drawの最後の...
if( y<0 ){ y=0; vy = -vy; }
を加えればよい。
終了行:
#navi(Processing/2.ちょっと発展)
* 2-12. 物理 [#l4e9490a]
次のプログラムは〇をx方向に往復運動をするものだった。
float x, y, dx;
void setup(){
size(400,400);
x = 0;
y = height / 2;
dx = 2;
}
void draw(){
fill(0);
rect(0,0,width,height);
fill(255);
circle(x, y, 20);
if( x < 0 || x > width ) { dx = -dx; }
x = x + dx;
}
次のスケッチは、物理法則をそれなりに模擬する。
初速度20m/s、角度thで投げ上げられた物体の位置を計算し、そ...
Setupでは、thに投げ上げの角度を代入し、フレームレートをfp...
float x, y, vx, vy, dt;
void setup(){
size(800,300);
x = 0;
y = 0;
float th = 75;
vx = 20 * cos(radians(th));
vy = 20 * sin(radians(th));
float fps = 120;
frameRate(fps);
dt = 1.0 / fps;
}
void draw(){
fill(0);
rect(0, 0, width, height);
applyMatrix( 10, 0, 5, 0, -10, height-5 );
fill(255);
circle(x, y, 2);
x = x + vx * dt;
y = y + vy * dt;
vy = vy - 9.8 * dt;
}
物体が地面で弾性的に跳ね返るようにするには、drawの最後の...
if( y<0 ){ y=0; vy = -vy; }
を加えればよい。
ページ名: