-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.php
35 lines (27 loc) · 1.04 KB
/
demo.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
<?php
namespace PHPhysics;
require_once __DIR__ . '/vendor/autoload.php';
use PHPhysics\Model\Body;
use PHPhysics\Model\Simulation;
$simulation = new Simulation();
$simulation->addBody(new Body(150, 250));
$simulation->addBody(new Body(150, 250));
$simulation->addBody(new Body(150, 250));
$simulation->addBody(new Body(150, 250));
$simulation->addBody(new Body(150, 250));
$simulation->addBody(new Body(150, 250));
$simulation->addBody(new Body(150, 250));
$simulation->addBody(new Body(150, 250));
$image = imagecreate(300, 300);
imagefilledrectangle($image, 0, 0, 300, 300, imagecolorallocate($image, 255, 255, 255));
$colorFactor = 8;
for($i = 0; $i < 25; $i++){
$simulation->nextStep();
/** @var Body $body */
foreach($simulation->getBodies() as $body){
$colorIntensity = 255 - $i * $colorFactor;
imagesetpixel($image, round($body->getX()), round($body->getY()), imagecolorallocate($image, $colorIntensity, $colorIntensity, $colorIntensity));
}
}
imageflip($image, IMG_FLIP_VERTICAL);
imagepng($image, 'demo.png');