回答編集履歴
1
見直しキャンペーン中
test
CHANGED
@@ -1,117 +1,60 @@
|
|
1
1
|
「そういうことじゃない!」ってのは承知しています^^;
|
2
|
-
|
3
2
|
ライブラリを使うとどのくらい簡単になるか試しました。
|
4
3
|
|
5
|
-
|
6
|
-
|
7
4
|
```Processing
|
8
|
-
|
9
5
|
import fisica.*;
|
10
|
-
|
11
|
-
|
12
6
|
|
13
7
|
FWorld world;
|
14
8
|
|
15
|
-
|
16
|
-
|
17
9
|
void setup() {
|
18
|
-
|
19
10
|
size(500, 500);
|
20
|
-
|
21
11
|
colorMode(HSB);
|
22
12
|
|
23
|
-
|
24
|
-
|
25
13
|
Fisica.init(this);
|
26
|
-
|
27
14
|
world = new FWorld();
|
28
|
-
|
29
15
|
world.setEdges();
|
30
|
-
|
31
16
|
world.setGravity(0, 0);
|
32
|
-
|
33
17
|
world.setGrabbable(false);
|
34
18
|
|
35
|
-
|
36
|
-
|
37
19
|
for (int i = 0; i < 3; i++) {
|
38
|
-
|
39
20
|
FBody ball = createBall();
|
40
|
-
|
41
21
|
ball.setPosition(random(50, width - 50), random(50, height - 50));
|
42
|
-
|
43
22
|
world.add(ball);
|
44
|
-
|
45
23
|
}
|
46
|
-
|
47
24
|
}
|
48
25
|
|
49
|
-
|
50
|
-
|
51
26
|
void draw() {
|
52
|
-
|
53
27
|
background(255);
|
54
|
-
|
55
28
|
world.step();
|
56
|
-
|
57
29
|
world.draw();
|
58
|
-
|
59
30
|
}
|
60
31
|
|
61
|
-
|
62
|
-
|
63
32
|
void contactStarted(FContact contact) {
|
64
|
-
|
65
33
|
FBody b1 = contact.getBody1();
|
66
|
-
|
67
34
|
FBody b2 = contact.getBody2();
|
68
|
-
|
69
35
|
if (b1.isStatic() || b2.isStatic()) return;
|
70
|
-
|
71
36
|
if (b1.getJoints().size() != 0 && b2.getJoints().size() != 0) return;
|
72
37
|
|
73
|
-
|
74
|
-
|
75
38
|
FRevoluteJoint joint = new FRevoluteJoint(b1, b2);
|
76
|
-
|
77
39
|
joint.setDrawable(false);
|
78
|
-
|
79
40
|
world.add(joint);
|
80
|
-
|
81
41
|
}
|
82
42
|
|
83
|
-
|
84
|
-
|
85
43
|
FBody createBall() {
|
86
|
-
|
87
44
|
FCircle ball = new FCircle(random(40, 60));
|
88
|
-
|
89
45
|
ball.setDamping(0);
|
90
|
-
|
91
46
|
ball.setRestitution(1);
|
92
|
-
|
93
47
|
ball.setVelocity(random(-300, 300), random(-300, 300));
|
94
|
-
|
95
48
|
ball.setFillColor(color(random(256), 128, 255));
|
96
|
-
|
97
49
|
ball.setNoStroke();
|
98
|
-
|
99
50
|
return ball;
|
100
|
-
|
101
51
|
}
|
102
52
|
|
103
|
-
|
104
|
-
|
105
53
|
// ちょい寂しいのでおまけ
|
106
|
-
|
107
54
|
void mousePressed() {
|
108
|
-
|
109
55
|
FBody ball = createBall();
|
110
|
-
|
111
56
|
ball.setPosition(mouseX, mouseY);
|
112
|
-
|
113
57
|
world.add(ball);
|
114
|
-
|
115
58
|
}
|
116
|
-
|
117
59
|
```
|
60
|
+
[fisica](http://www.ricardmarxer.com/fisica/)
|