質問編集履歴
2
プログラムの追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -23,6 +23,112 @@
|
|
23
23
|
### 該当のソースコード
|
24
24
|
|
25
25
|
```processing
|
26
|
+
import ddf.minim.*;
|
27
|
+
import ddf.minim.analysis.*;
|
28
|
+
import ddf.minim.effects.*;
|
29
|
+
import ddf.minim.signals.*;
|
30
|
+
import ddf.minim.spi.*;
|
31
|
+
import ddf.minim.ugens.*;
|
32
|
+
|
33
|
+
Minim minim;
|
34
|
+
AudioPlayer player;
|
35
|
+
float playerIn;
|
36
|
+
float x;
|
37
|
+
float y;
|
38
|
+
int buffersize = 512;
|
39
|
+
|
40
|
+
int NUM = 10; //パーティクルの数
|
41
|
+
//パーティクルを格納する配列
|
42
|
+
ParticleVec2[] particles = new ParticleVec2[NUM];
|
43
|
+
|
44
|
+
void setup() {
|
45
|
+
fullScreen();
|
46
|
+
smooth();
|
47
|
+
frameRate(60);
|
48
|
+
colorMode(HSB, 360, 100, 100, 100);
|
49
|
+
|
50
|
+
minim = new Minim(this);
|
51
|
+
player = minim.loadFile("Mountain.mp3");
|
52
|
+
player.loop();
|
53
|
+
|
54
|
+
for (int i = 0; i < NUM; i++) {
|
55
|
+
particles[i] = new ParticleVec2();
|
56
|
+
particles[i].location.set(width/2.0, height/2.3);
|
57
|
+
}
|
58
|
+
}
|
59
|
+
|
60
|
+
void draw() {
|
61
|
+
//背景をフェードさせる
|
62
|
+
fill(0, 30);
|
63
|
+
rect(0, 0, width, height);
|
64
|
+
fill(100);
|
65
|
+
|
66
|
+
//木
|
67
|
+
colorMode(RGB);
|
68
|
+
Tree(30, width/2, height, PI, width/8);
|
69
|
+
|
70
|
+
//パーティクルの位置を更新して描画
|
71
|
+
for (int i = 0; i < NUM; i++) {
|
72
|
+
particles[i].update();
|
73
|
+
particles[i].draw();
|
74
|
+
particles[i].bounceOffWalls();
|
75
|
+
}
|
76
|
+
|
77
|
+
//地面
|
78
|
+
fill(#959592);
|
79
|
+
rect(0, 1030, 2000, 50);
|
80
|
+
}
|
81
|
+
|
82
|
+
//木の生成
|
83
|
+
void Tree(float strokeWeight, float x, float y, float rotate, float length) {
|
84
|
+
pushMatrix(); //座標を一時保存
|
85
|
+
translate(x, y); //座標移動
|
86
|
+
rotate(rotate); //座標回転
|
87
|
+
strokeWeight(strokeWeight); //線の輪郭線の太さ
|
88
|
+
stroke(#E57409); //線の色
|
89
|
+
line(0, 0, 0, length); //線の描画,配列の長さ
|
90
|
+
popMatrix(); //変更した座標を元に戻す
|
91
|
+
if (strokeWeight<2)return;
|
92
|
+
if (x%5>3 && strokeWeight<3)return;
|
93
|
+
Tree(strokeWeight*2/3, x-sin(rotate)*length, y+cos(rotate)*length, rotate-PI/10, length*2/3);
|
94
|
+
Tree(strokeWeight*2/3, x-sin(rotate)*length, y+cos(rotate)*length, rotate+PI/10, length*2/3);
|
95
|
+
}
|
96
|
+
|
97
|
+
void mouseClicked() {
|
98
|
+
//パーティクルの数だけくりかえし
|
99
|
+
for (int i = 0; i < NUM; i++) {
|
100
|
+
|
101
|
+
//ランダムに加速度を設定 - ランダムの範囲を中央からの距離に
|
102
|
+
float angle = random(PI * 2.0);
|
103
|
+
float length = random(20);
|
104
|
+
float posX = cos(angle) * length;
|
105
|
+
float posY = sin(angle) * length;
|
106
|
+
particles[i].acceleration.set(posX, posY);
|
107
|
+
//下向きに0.1の重力
|
108
|
+
particles[i].gravity.set(0.0, 0.1);
|
109
|
+
//摩擦を0.01に
|
110
|
+
particles[i].friction = 0.01;
|
111
|
+
PVector force = new PVector(cos(angle) * length, sin(angle) * length);
|
112
|
+
particles[i].addForce(force);
|
113
|
+
}
|
114
|
+
}
|
115
|
+
|
116
|
+
void keyPressed(){
|
117
|
+
for (int i = 0; i < NUM; i++) {
|
118
|
+
particles[i] = new ParticleVec2();
|
119
|
+
particles[i].location.set(width/2.0, height/2.3);
|
120
|
+
}
|
121
|
+
}
|
122
|
+
|
123
|
+
void stop() {
|
124
|
+
minim.stop();
|
125
|
+
super.stop();
|
126
|
+
}
|
127
|
+
|
128
|
+
|
129
|
+
// ↑メイン ↓物理演算
|
130
|
+
|
131
|
+
|
26
132
|
// 物体の運動を計算(運動方程式)
|
27
133
|
class ParticleVec2 {
|
28
134
|
PVector location; // 位置
|
1
ソースコードの追加ミス
title
CHANGED
File without changes
|
body
CHANGED
@@ -23,8 +23,7 @@
|
|
23
23
|
### 該当のソースコード
|
24
24
|
|
25
25
|
```processing
|
26
|
-
ソースコード
|
27
|
-
|
26
|
+
// 物体の運動を計算(運動方程式)
|
28
27
|
class ParticleVec2 {
|
29
28
|
PVector location; // 位置
|
30
29
|
PVector velocity; // 速度
|
@@ -111,6 +110,7 @@
|
|
111
110
|
acceleration.add(force); //力を加速度に加える
|
112
111
|
}
|
113
112
|
}
|
113
|
+
```
|
114
114
|
|
115
115
|
### 試したこと
|
116
116
|
|