-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbounce.php
56 lines (44 loc) · 1016 Bytes
/
bounce.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
$td = 0.05;
$ballCount = 7;
$maxH = 50;
$g = 9.8;
$a = -$g * $td;
$maxV = sqrt($maxH * 2 * $g);
$balls = [];
for ($i = 0; $i < $ballCount; $i++) {
$balls[$i] = [
'v' => $maxV * (random_int(50, 100) / 100),
'h' => 0,
'c' => chr(random_int(65, 90))
];
}
do {
foreach ($balls as $key => $ball) {
$v = $ball['v'];
$h = $ball['h'];
$h = max(
0,
$h + ($v * $td) + (0.5 * $a * $td * $td)
);
if ($h === 0) {
$v = -0.75 * $v;
}
$v += $a;
if ((int) $v === 0 && (int) $h === 0) {
$v = $maxV * (random_int(90, 100) / 100);
}
$balls[$key]['v'] = $v;
$balls[$key]['h'] = $h;
}
system('clear');
foreach (range($maxH, 1) as $h) {
foreach ($balls as $ball) {
if ((int) $ball['h'] === $h) {
echo $ball['c'].' ';
}
}
echo "\n";
}
usleep(10000);
} while (true);