Skip to content

Commit 4718182

Browse files
mihailgaberovmihailgaberov
mihailgaberov
authored and
mihailgaberov
committed
💄 Added 75 balls png. Fine tuning the animation.
1 parent ba01e82 commit 4718182

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+96
-23
lines changed

index.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.js

+94-21
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import Matter from 'matter-js'
22

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
47

58
export default class App {
69
static init () {
@@ -20,33 +23,97 @@ export default class App {
2023
engine: engine,
2124
options: {
2225
wireframes: false,
23-
width: 550,
24-
height: 550,
26+
width: CANVAS_WIDTH,
27+
height: CANVAS_HEIGHT,
2528
background: 'transparent'
2629
}
2730
})
2831

2932
const balls = []
3033
const ballImagePaths = [
3134
'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',
3240
'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',
3346
'static/images/13.png',
47+
'static/images/14.png',
48+
'static/images/15.png',
49+
'static/images/16.png',
3450
'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',
3557
'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',
3666
'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',
3777
'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',
3883
'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',
3991
'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',
4099
'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',
41108
'static/images/75.png',
42109
]
43110

44111
const createBall = () => {
45112
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,
50117
render: {
51118
sprite: {
52119
texture: ballImagePaths[Math.round(Math.random() * (ballImagePaths.length - 1))]
@@ -59,19 +126,19 @@ export default class App {
59126

60127
const onRenderTick = () => {
61128
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 })
64131
}
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 })
67134
}
68135

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 })
71138
}
72139

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 })
75142
}
76143
})
77144
}
@@ -98,8 +165,8 @@ export default class App {
98165
return body
99166
}
100167

101-
const sW = 550
102-
const sH = 550
168+
const sW = CANVAS_WIDTH
169+
const sH = CANVAS_WIDTH
103170
const m = Math.min(sW, sH)
104171
const rat = 1 / 4.5 * 2
105172
const r = m * rat
@@ -113,10 +180,16 @@ export default class App {
113180
const cx2 = x2 * r + sW / 2
114181
const cy2 = y2 * r + sH / 2
115182
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',
120193
lineWidth: 0
121194
}
122195
}

index.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ body {
1111
background: url(static/images/blower.png);
1212
background-repeat: no-repeat;
1313
background-size: 140%;
14-
background-position: -252px -117px;
14+
background-position: -252px -113px;
1515
transform: translateY(-50%) translateX(-50%);
1616

1717
&:after {

static/images/10.png

24.2 KB

static/images/11.png

24.2 KB

static/images/12.png

24.4 KB

static/images/14.png

24.3 KB

static/images/15.png

24.3 KB

static/images/16.png

24.2 KB

static/images/18.png

24.4 KB

static/images/19.png

24.4 KB

static/images/2.png

24.2 KB

static/images/20.png

24.4 KB

static/images/21.png

24.4 KB

static/images/22.png

24.4 KB

static/images/23.png

24.4 KB

static/images/25.png

24.3 KB

static/images/26.png

24.4 KB

static/images/27.png

24.2 KB

static/images/28.png

24.4 KB

static/images/29.png

24.4 KB

static/images/3.png

24.3 KB

static/images/30.png

24.4 KB

static/images/31.png

24.1 KB

static/images/32.png

24.3 KB

static/images/34.png

24.4 KB

static/images/35.png

24.4 KB

static/images/36.png

24.3 KB

static/images/37.png

24.3 KB

static/images/38.png

24.3 KB

static/images/39.png

24.4 KB

static/images/4.png

24.2 KB

static/images/40.png

24.3 KB

static/images/41.png

24.2 KB

static/images/42.png

24.4 KB

static/images/43.png

24.3 KB

static/images/45.png

24.3 KB

static/images/46.png

24.1 KB

static/images/47.png

24 KB

static/images/48.png

24.2 KB

static/images/49.png

24.2 KB

static/images/5.png

24.4 KB

static/images/51.png

24.2 KB

static/images/52.png

24.3 KB

static/images/53.png

24.3 KB

static/images/54.png

24.2 KB

static/images/55.png

24.1 KB

static/images/56.png

24.3 KB

static/images/57.png

24.2 KB

static/images/59.png

24.3 KB

static/images/6.png

24.3 KB

static/images/60.png

24.2 KB

static/images/61.png

24.2 KB

static/images/62.png

24.3 KB

static/images/63.png

24.4 KB

static/images/64.png

24.4 KB

static/images/65.png

24.5 KB

static/images/67.png

24.4 KB

static/images/68.png

24.4 KB

static/images/69.png

24.5 KB

static/images/70.png

24.4 KB

static/images/71.png

24.2 KB

static/images/72.png

24.4 KB

static/images/73.png

24.4 KB

static/images/74.png

24.3 KB

static/images/8.png

24.3 KB

static/images/9.png

24.3 KB

0 commit comments

Comments
 (0)