1
1
import Matter from 'matter-js'
2
2
3
- const BALLS_COUNT = 44
3
+ const BALLS_COUNT = 75
4
+ const BALL_RADIUS = 10
5
+ const CANVAS_WIDTH = 550
6
+ const CANVAS_HEIGHT = 550
4
7
5
8
export default class App {
6
9
static init ( ) {
@@ -20,33 +23,97 @@ export default class App {
20
23
engine : engine ,
21
24
options : {
22
25
wireframes : false ,
23
- width : 550 ,
24
- height : 550 ,
26
+ width : CANVAS_WIDTH ,
27
+ height : CANVAS_HEIGHT ,
25
28
background : 'transparent'
26
29
}
27
30
} )
28
31
29
32
const balls = [ ]
30
33
const ballImagePaths = [
31
34
'static/images/1.png' ,
35
+ 'static/images/2.png' ,
36
+ 'static/images/3.png' ,
37
+ 'static/images/4.png' ,
38
+ 'static/images/5.png' ,
39
+ 'static/images/6.png' ,
32
40
'static/images/7.png' ,
41
+ 'static/images/8.png' ,
42
+ 'static/images/9.png' ,
43
+ 'static/images/10.png' ,
44
+ 'static/images/11.png' ,
45
+ 'static/images/12.png' ,
33
46
'static/images/13.png' ,
47
+ 'static/images/14.png' ,
48
+ 'static/images/15.png' ,
49
+ 'static/images/16.png' ,
34
50
'static/images/17.png' ,
51
+ 'static/images/18.png' ,
52
+ 'static/images/19.png' ,
53
+ 'static/images/20.png' ,
54
+ 'static/images/21.png' ,
55
+ 'static/images/22.png' ,
56
+ 'static/images/23.png' ,
35
57
'static/images/24.png' ,
58
+ 'static/images/25.png' ,
59
+ 'static/images/26.png' ,
60
+ 'static/images/27.png' ,
61
+ 'static/images/28.png' ,
62
+ 'static/images/29.png' ,
63
+ 'static/images/30.png' ,
64
+ 'static/images/31.png' ,
65
+ 'static/images/32.png' ,
36
66
'static/images/33.png' ,
67
+ 'static/images/34.png' ,
68
+ 'static/images/35.png' ,
69
+ 'static/images/36.png' ,
70
+ 'static/images/37.png' ,
71
+ 'static/images/38.png' ,
72
+ 'static/images/39.png' ,
73
+ 'static/images/40.png' ,
74
+ 'static/images/41.png' ,
75
+ 'static/images/42.png' ,
76
+ 'static/images/43.png' ,
37
77
'static/images/44.png' ,
78
+ 'static/images/45.png' ,
79
+ 'static/images/46.png' ,
80
+ 'static/images/47.png' ,
81
+ 'static/images/48.png' ,
82
+ 'static/images/49.png' ,
38
83
'static/images/50.png' ,
84
+ 'static/images/51.png' ,
85
+ 'static/images/52.png' ,
86
+ 'static/images/53.png' ,
87
+ 'static/images/54.png' ,
88
+ 'static/images/55.png' ,
89
+ 'static/images/56.png' ,
90
+ 'static/images/57.png' ,
39
91
'static/images/58.png' ,
92
+ 'static/images/59.png' ,
93
+ 'static/images/60.png' ,
94
+ 'static/images/61.png' ,
95
+ 'static/images/62.png' ,
96
+ 'static/images/63.png' ,
97
+ 'static/images/64.png' ,
98
+ 'static/images/65.png' ,
40
99
'static/images/66.png' ,
100
+ 'static/images/67.png' ,
101
+ 'static/images/68.png' ,
102
+ 'static/images/69.png' ,
103
+ 'static/images/70.png' ,
104
+ 'static/images/71.png' ,
105
+ 'static/images/72.png' ,
106
+ 'static/images/73.png' ,
107
+ 'static/images/74.png' ,
41
108
'static/images/75.png' ,
42
109
]
43
110
44
111
const createBall = ( ) => {
45
112
const ball = Bodies . circle (
46
- 300 ,
47
- render . canvas . height / 2 ,
48
- 20 , {
49
- restitution : 1 ,
113
+ render . canvas . width / 2 - BALL_RADIUS ,
114
+ render . canvas . height / 2 - 2 * BALL_RADIUS ,
115
+ BALL_RADIUS , {
116
+ restitution : 1.03 ,
50
117
render : {
51
118
sprite : {
52
119
texture : ballImagePaths [ Math . round ( Math . random ( ) * ( ballImagePaths . length - 1 ) ) ]
@@ -59,19 +126,19 @@ export default class App {
59
126
60
127
const onRenderTick = ( ) => {
61
128
balls . forEach ( ball => {
62
- if ( ball . position . y >= render . canvas . height - 60 ) {
63
- Body . applyForce ( ball , { x : ball . position . x , y : ball . position . y } , { x : .005 , y : - 0.07 } )
129
+ if ( ball . position . y >= render . canvas . height - 100 ) {
130
+ Body . applyForce ( ball , { x : ball . position . x , y : ball . position . y } , { x : 0.01 , y : - 0.01 } )
64
131
}
65
- if ( ball . position . y < ball . circleRadius ) {
66
- Body . applyForce ( ball , { x : ball . position . x , y : ball . position . y } , { x : - 0.005 , y : 0.05 } )
132
+ if ( ball . position . y < 120 ) {
133
+ Body . applyForce ( ball , { x : ball . position . x , y : ball . position . y } , { x : - 0.01 , y : 0.01 } )
67
134
}
68
135
69
- if ( ball . position . x < ball . circleRadius ) {
70
- Body . applyForce ( ball , { x : ball . position . x , y : ball . position . y } , { x : 0.05 , y : - 0.005 } )
136
+ if ( ball . position . x < 80 ) {
137
+ Body . applyForce ( ball , { x : ball . position . x , y : ball . position . y } , { x : 0.01 , y : - 0.01 } )
71
138
}
72
139
73
- if ( ball . position . x > render . canvas . width - 60 ) {
74
- Body . applyForce ( ball , { x : ball . position . x , y : ball . position . y } , { x : - 0.05 , y : 0.005 } )
140
+ if ( ball . position . x > render . canvas . width - 80 ) {
141
+ Body . applyForce ( ball , { x : ball . position . x , y : ball . position . y } , { x : - 0.01 , y : 0.01 } )
75
142
}
76
143
} )
77
144
}
@@ -98,8 +165,8 @@ export default class App {
98
165
return body
99
166
}
100
167
101
- const sW = 550
102
- const sH = 550
168
+ const sW = CANVAS_WIDTH
169
+ const sH = CANVAS_WIDTH
103
170
const m = Math . min ( sW , sH )
104
171
const rat = 1 / 4.5 * 2
105
172
const r = m * rat
@@ -113,10 +180,16 @@ export default class App {
113
180
const cx2 = x2 * r + sW / 2
114
181
const cy2 = y2 * r + sH / 2
115
182
addRect ( {
116
- x : cx2 , y : cy2 , w : 10 / 1000 * m , h : 300 / 1000 * m , options : {
117
- angle : angle2 , isStatic : true , density : 1 , render : {
118
- fillStyle : 'transparent' ,
119
- strokeStyle : 'white' ,
183
+ x : cx2 ,
184
+ y : cy2 ,
185
+ w : 10 / 1000 * m ,
186
+ h : 300 / 1000 * m ,
187
+ options : {
188
+ angle : angle2 ,
189
+ isStatic : true ,
190
+ density : 1 ,
191
+ render : {
192
+ fillStyle : 'red' ,
120
193
lineWidth : 0
121
194
}
122
195
}
0 commit comments