回答編集履歴
1
見直しキャンペーン中
answer
CHANGED
@@ -1,62 +1,62 @@
|
|
1
|
-
> ellipse(location.x, location.y, playerIn, playerIn);
|
2
|
-
> //translate(location.x/1.4,location.y/2);//位置はずれたが同じ動きでバウンド位置もずれる
|
3
|
-
> //ellipse(location.x, location.y, playerIn, playerIn);
|
4
|
-
|
5
|
-
locationをいじってもvelocityやaccelerationが同じなので、同じ動きになってしまいます。
|
6
|
-
|
7
|
-
ParticleVec2は円ひとつを表すオブジェクトですから、円の個数分作らなければなりません。
|
8
|
-
|
9
|
-
最初の5個とそれぞれの10個、合計55個のParticleVec2を作ります。
|
10
|
-
配列に入れるときに11個ずつ同じ位置になるようにすれば、後はほとんど変える必要はありません。
|
11
|
-
|
12
|
-
キープレスでリセットしたいので配列に入れる処理を関数に分け、setupとkeyPressedで呼ぶようにします。
|
13
|
-
```Processing
|
14
|
-
//省略
|
15
|
-
|
16
|
-
int NUM = 5 + 5 * 10; //パーティクルの数 55個 最初の5個+それぞれに10個
|
17
|
-
ParticleVec2[] particles = new ParticleVec2[NUM];
|
18
|
-
|
19
|
-
void setup() {
|
20
|
-
fullScreen();
|
21
|
-
smooth();
|
22
|
-
frameRate(60);
|
23
|
-
colorMode(HSB, 360, 100, 100, 100);
|
24
|
-
|
25
|
-
minim = new Minim(this);
|
26
|
-
player = minim.loadFile("Mountain.mp3");
|
27
|
-
player.loop();
|
28
|
-
|
29
|
-
resetParticles();
|
30
|
-
}
|
31
|
-
|
32
|
-
void resetParticles() {
|
33
|
-
// forいっこで書けるけど調整しやすいようにグループごとに設定した
|
34
|
-
int w=width/12;
|
35
|
-
int offset=width/12*3;
|
36
|
-
for (int i = 0; i < 11; i++) { // 左端
|
37
|
-
particles[i] = new ParticleVec2();
|
38
|
-
particles[i].location.set(w+offset, height/2.3);
|
39
|
-
}
|
40
|
-
for (int i = 11; i < 22; i++) {
|
41
|
-
particles[i] = new ParticleVec2();
|
42
|
-
particles[i].location.set(w*2+offset, height/2.3);
|
43
|
-
}
|
44
|
-
for (int i = 22; i < 33; i++) { // 真ん中
|
45
|
-
particles[i] = new ParticleVec2();
|
46
|
-
particles[i].location.set(w*3+offset, height/2.3);
|
47
|
-
}
|
48
|
-
for (int i = 33; i < 44; i++) {
|
49
|
-
particles[i] = new ParticleVec2();
|
50
|
-
particles[i].location.set(w*4+offset, height/2.3);
|
51
|
-
}
|
52
|
-
for (int i = 44; i < 55; i++) { // 右端
|
53
|
-
particles[i] = new ParticleVec2();
|
54
|
-
particles[i].location.set(w*5+offset, height/2.3);
|
55
|
-
}
|
56
|
-
}
|
57
|
-
|
58
|
-
void keyPressed() {
|
59
|
-
resetParticles();
|
60
|
-
}
|
61
|
-
//省略
|
1
|
+
> ellipse(location.x, location.y, playerIn, playerIn);
|
2
|
+
> //translate(location.x/1.4,location.y/2);//位置はずれたが同じ動きでバウンド位置もずれる
|
3
|
+
> //ellipse(location.x, location.y, playerIn, playerIn);
|
4
|
+
|
5
|
+
`location`をいじっても`velocity`や`acceleration`が同じなので、同じ動きになってしまいます。
|
6
|
+
|
7
|
+
`ParticleVec2`は円ひとつを表すオブジェクトですから、円の個数分作らなければなりません。
|
8
|
+
|
9
|
+
最初の5個とそれぞれの10個、合計55個の`ParticleVec2`を作ります。
|
10
|
+
配列に入れるときに11個ずつ同じ位置になるようにすれば、後はほとんど変える必要はありません。
|
11
|
+
|
12
|
+
キープレスでリセットしたいので配列に入れる処理を関数に分け、`setup`と`keyPressed`で呼ぶようにします。
|
13
|
+
```Processing
|
14
|
+
//省略
|
15
|
+
|
16
|
+
int NUM = 5 + 5 * 10; //パーティクルの数 55個 最初の5個+それぞれに10個
|
17
|
+
ParticleVec2[] particles = new ParticleVec2[NUM];
|
18
|
+
|
19
|
+
void setup() {
|
20
|
+
fullScreen();
|
21
|
+
smooth();
|
22
|
+
frameRate(60);
|
23
|
+
colorMode(HSB, 360, 100, 100, 100);
|
24
|
+
|
25
|
+
minim = new Minim(this);
|
26
|
+
player = minim.loadFile("Mountain.mp3");
|
27
|
+
player.loop();
|
28
|
+
|
29
|
+
resetParticles();
|
30
|
+
}
|
31
|
+
|
32
|
+
void resetParticles() {
|
33
|
+
// forいっこで書けるけど調整しやすいようにグループごとに設定した
|
34
|
+
int w=width/12;
|
35
|
+
int offset=width/12*3;
|
36
|
+
for (int i = 0; i < 11; i++) { // 左端
|
37
|
+
particles[i] = new ParticleVec2();
|
38
|
+
particles[i].location.set(w+offset, height/2.3);
|
39
|
+
}
|
40
|
+
for (int i = 11; i < 22; i++) {
|
41
|
+
particles[i] = new ParticleVec2();
|
42
|
+
particles[i].location.set(w*2+offset, height/2.3);
|
43
|
+
}
|
44
|
+
for (int i = 22; i < 33; i++) { // 真ん中
|
45
|
+
particles[i] = new ParticleVec2();
|
46
|
+
particles[i].location.set(w*3+offset, height/2.3);
|
47
|
+
}
|
48
|
+
for (int i = 33; i < 44; i++) {
|
49
|
+
particles[i] = new ParticleVec2();
|
50
|
+
particles[i].location.set(w*4+offset, height/2.3);
|
51
|
+
}
|
52
|
+
for (int i = 44; i < 55; i++) { // 右端
|
53
|
+
particles[i] = new ParticleVec2();
|
54
|
+
particles[i].location.set(w*5+offset, height/2.3);
|
55
|
+
}
|
56
|
+
}
|
57
|
+
|
58
|
+
void keyPressed() {
|
59
|
+
resetParticles();
|
60
|
+
}
|
61
|
+
//省略
|
62
62
|
```
|