質問編集履歴

2

プログラムの追加

2019/12/07 10:45

投稿

msw
msw

スコア9

test CHANGED
File without changes
test CHANGED
@@ -48,6 +48,218 @@
48
48
 
49
49
  ```processing
50
50
 
51
+ import ddf.minim.*;
52
+
53
+ import ddf.minim.analysis.*;
54
+
55
+ import ddf.minim.effects.*;
56
+
57
+ import ddf.minim.signals.*;
58
+
59
+ import ddf.minim.spi.*;
60
+
61
+ import ddf.minim.ugens.*;
62
+
63
+
64
+
65
+ Minim minim;
66
+
67
+ AudioPlayer player;
68
+
69
+ float playerIn;
70
+
71
+ float x;
72
+
73
+ float y;
74
+
75
+ int buffersize = 512;
76
+
77
+
78
+
79
+ int NUM = 10; //パーティクルの数
80
+
81
+ //パーティクルを格納する配列
82
+
83
+ ParticleVec2[] particles = new ParticleVec2[NUM];
84
+
85
+
86
+
87
+ void setup() {
88
+
89
+ fullScreen();
90
+
91
+ smooth();
92
+
93
+ frameRate(60);
94
+
95
+ colorMode(HSB, 360, 100, 100, 100);
96
+
97
+
98
+
99
+ minim = new Minim(this);
100
+
101
+ player = minim.loadFile("Mountain.mp3");
102
+
103
+ player.loop();
104
+
105
+
106
+
107
+ for (int i = 0; i < NUM; i++) {
108
+
109
+ particles[i] = new ParticleVec2();
110
+
111
+ particles[i].location.set(width/2.0, height/2.3);
112
+
113
+ }
114
+
115
+ }
116
+
117
+
118
+
119
+ void draw() {
120
+
121
+ //背景をフェードさせる
122
+
123
+ fill(0, 30);
124
+
125
+ rect(0, 0, width, height);
126
+
127
+ fill(100);
128
+
129
+
130
+
131
+ //木
132
+
133
+ colorMode(RGB);
134
+
135
+ Tree(30, width/2, height, PI, width/8);
136
+
137
+
138
+
139
+ //パーティクルの位置を更新して描画
140
+
141
+ for (int i = 0; i < NUM; i++) {
142
+
143
+ particles[i].update();
144
+
145
+ particles[i].draw();
146
+
147
+ particles[i].bounceOffWalls();
148
+
149
+ }
150
+
151
+
152
+
153
+ //地面
154
+
155
+ fill(#959592);
156
+
157
+ rect(0, 1030, 2000, 50);
158
+
159
+ }
160
+
161
+
162
+
163
+ //木の生成
164
+
165
+ void Tree(float strokeWeight, float x, float y, float rotate, float length) {
166
+
167
+ pushMatrix(); //座標を一時保存
168
+
169
+ translate(x, y); //座標移動
170
+
171
+ rotate(rotate); //座標回転
172
+
173
+ strokeWeight(strokeWeight); //線の輪郭線の太さ
174
+
175
+ stroke(#E57409); //線の色
176
+
177
+ line(0, 0, 0, length); //線の描画,配列の長さ
178
+
179
+ popMatrix(); //変更した座標を元に戻す
180
+
181
+ if (strokeWeight<2)return;
182
+
183
+ if (x%5>3 && strokeWeight<3)return;
184
+
185
+ Tree(strokeWeight*2/3, x-sin(rotate)*length, y+cos(rotate)*length, rotate-PI/10, length*2/3);
186
+
187
+ Tree(strokeWeight*2/3, x-sin(rotate)*length, y+cos(rotate)*length, rotate+PI/10, length*2/3);
188
+
189
+ }
190
+
191
+
192
+
193
+ void mouseClicked() {
194
+
195
+ //パーティクルの数だけくりかえし
196
+
197
+ for (int i = 0; i < NUM; i++) {
198
+
199
+
200
+
201
+ //ランダムに加速度を設定 - ランダムの範囲を中央からの距離に
202
+
203
+ float angle = random(PI * 2.0);
204
+
205
+ float length = random(20);
206
+
207
+ float posX = cos(angle) * length;
208
+
209
+ float posY = sin(angle) * length;
210
+
211
+ particles[i].acceleration.set(posX, posY);
212
+
213
+ //下向きに0.1の重力
214
+
215
+ particles[i].gravity.set(0.0, 0.1);
216
+
217
+ //摩擦を0.01に
218
+
219
+ particles[i].friction = 0.01;
220
+
221
+ PVector force = new PVector(cos(angle) * length, sin(angle) * length);
222
+
223
+ particles[i].addForce(force);
224
+
225
+ }
226
+
227
+ }
228
+
229
+
230
+
231
+ void keyPressed(){
232
+
233
+ for (int i = 0; i < NUM; i++) {
234
+
235
+ particles[i] = new ParticleVec2();
236
+
237
+ particles[i].location.set(width/2.0, height/2.3);
238
+
239
+ }
240
+
241
+ }
242
+
243
+
244
+
245
+ void stop() {
246
+
247
+ minim.stop();
248
+
249
+ super.stop();
250
+
251
+ }
252
+
253
+
254
+
255
+
256
+
257
+ // ↑メイン ↓物理演算
258
+
259
+
260
+
261
+
262
+
51
263
  // 物体の運動を計算(運動方程式)
52
264
 
53
265
  class ParticleVec2 {

1

ソースコードの追加ミス

2019/12/07 10:45

投稿

msw
msw

スコア9

test CHANGED
File without changes
test CHANGED
@@ -48,9 +48,7 @@
48
48
 
49
49
  ```processing
50
50
 
51
- ソースコード
52
-
53
- ```// 物体の運動を計算(運動方程式)
51
+ // 物体の運動を計算(運動方程式)
54
52
 
55
53
  class ParticleVec2 {
56
54
 
@@ -224,6 +222,8 @@
224
222
 
225
223
  }
226
224
 
225
+ ```
226
+
227
227
 
228
228
 
229
229
  ### 試したこと