回答編集履歴

1

見直しキャンペーン中

2023/07/17 06:26

投稿

TN8001
TN8001

スコア9396

test CHANGED
@@ -1,123 +1,62 @@
1
1
  > ellipse(location.x, location.y, playerIn, playerIn);
2
-
3
2
  > //translate(location.x/1.4,location.y/2);//位置はずれたが同じ動きでバウンド位置もずれる
4
-
5
3
  > //ellipse(location.x, location.y, playerIn, playerIn);
6
4
 
5
+ `location`をいじっても`velocity`や`acceleration`が同じなので、同じ動きになってしまいます。
7
6
 
7
+ `ParticleVec2`は円ひとつを表すオブジェクトですから、円の個数分作らなければなりません。
8
8
 
9
- locationをいじってもvelocityやaccelerationが同じなので、同じ動きになってしまいます。
10
-
11
-
12
-
13
- ParticleVec2は円ひとつを表すオブジェクトですから、円の個数分作らなければなりません。
14
-
15
-
16
-
17
- 最初の5個とそれぞれの10個、合計55個のParticleVec2を作ります。
9
+ 最初の5個とそれぞれの10個、合計55個の`ParticleVec2`を作ります。
18
-
19
10
  配列に入れるときに11個ずつ同じ位置になるようにすれば、後はほとんど変える必要はありません。
20
11
 
21
-
22
-
23
- キープレスでリセットしたいので配列に入れる処理を関数に分け、setupとkeyPressedで呼ぶようにします。
12
+ キープレスでリセットしたいので配列に入れる処理を関数に分け、`setup``keyPressed`で呼ぶようにします。
24
-
25
13
  ```Processing
26
-
27
14
  //省略
28
15
 
29
-
30
-
31
16
  int NUM = 5 + 5 * 10; //パーティクルの数 55個 最初の5個+それぞれに10個
32
-
33
17
  ParticleVec2[] particles = new ParticleVec2[NUM];
34
18
 
35
-
36
-
37
19
  void setup() {
38
-
39
20
  fullScreen();
40
-
41
21
  smooth();
42
-
43
22
  frameRate(60);
44
-
45
23
  colorMode(HSB, 360, 100, 100, 100);
46
24
 
47
-
48
-
49
25
  minim = new Minim(this);
50
-
51
26
  player = minim.loadFile("Mountain.mp3");
52
-
53
27
  player.loop();
54
28
 
55
-
56
-
57
29
  resetParticles();
58
-
59
30
  }
60
31
 
61
-
62
-
63
32
  void resetParticles() {
64
-
65
33
  // forいっこで書けるけど調整しやすいようにグループごとに設定した
66
-
67
34
  int w=width/12;
68
-
69
35
  int offset=width/12*3;
70
-
71
36
  for (int i = 0; i < 11; i++) { // 左端
72
-
73
37
  particles[i] = new ParticleVec2();
74
-
75
38
  particles[i].location.set(w+offset, height/2.3);
76
-
77
39
  }
78
-
79
40
  for (int i = 11; i < 22; i++) {
80
-
81
41
  particles[i] = new ParticleVec2();
82
-
83
42
  particles[i].location.set(w*2+offset, height/2.3);
84
-
85
43
  }
86
-
87
44
  for (int i = 22; i < 33; i++) { // 真ん中
88
-
89
45
  particles[i] = new ParticleVec2();
90
-
91
46
  particles[i].location.set(w*3+offset, height/2.3);
92
-
93
47
  }
94
-
95
48
  for (int i = 33; i < 44; i++) {
96
-
97
49
  particles[i] = new ParticleVec2();
98
-
99
50
  particles[i].location.set(w*4+offset, height/2.3);
100
-
101
51
  }
102
-
103
52
  for (int i = 44; i < 55; i++) { // 右端
104
-
105
53
  particles[i] = new ParticleVec2();
106
-
107
54
  particles[i].location.set(w*5+offset, height/2.3);
108
-
109
55
  }
110
-
111
56
  }
112
57
 
113
-
114
-
115
58
  void keyPressed() {
116
-
117
59
  resetParticles();
118
-
119
60
  }
120
-
121
61
  //省略
122
-
123
62
  ```