updated virtual cannon script
This commit is contained in:
parent
1a3e0d31db
commit
b736be2b89
2 changed files with 42919 additions and 4 deletions
42903
images/virtual_cannon.ppm
Normal file
42903
images/virtual_cannon.ppm
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -4,8 +4,13 @@ declare(strict_types=1);
|
||||||
|
|
||||||
include __DIR__ . '/../vendor/autoload.php';
|
include __DIR__ . '/../vendor/autoload.php';
|
||||||
|
|
||||||
|
use ItsAMirko\RayTracer\Canvas\Canvas;
|
||||||
|
use ItsAMirko\RayTracer\Canvas\CanvasPpmFileWriter;
|
||||||
|
use ItsAMirko\RayTracer\Primitives\Color;
|
||||||
use ItsAMirko\RayTracer\Primitives\Point;
|
use ItsAMirko\RayTracer\Primitives\Point;
|
||||||
use ItsAMirko\RayTracer\Primitives\Vector;
|
use ItsAMirko\RayTracer\Primitives\Vector;
|
||||||
|
use League\Flysystem\Adapter\Local;
|
||||||
|
use League\Flysystem\Filesystem;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Projectile
|
* Class Projectile
|
||||||
|
|
@ -39,7 +44,6 @@ class Environment
|
||||||
public $wind;
|
public $wind;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function tick(Environment $environment, Projectile $projectile): Projectile
|
function tick(Environment $environment, Projectile $projectile): Projectile
|
||||||
{
|
{
|
||||||
$projectile->position = $projectile->position->plusVector($projectile->velocity);
|
$projectile->position = $projectile->position->plusVector($projectile->velocity);
|
||||||
|
|
@ -54,9 +58,17 @@ $environment->wind = new Vector(-0.01, 0.0, 0.0);
|
||||||
|
|
||||||
$projectile = new Projectile();
|
$projectile = new Projectile();
|
||||||
$projectile->position = new Point(0.0, 1.0, 0.0);
|
$projectile->position = new Point(0.0, 1.0, 0.0);
|
||||||
$projectile->velocity = (new Vector(1.0, 1.0, 0.0))->normalize();
|
$projectile->velocity = (new Vector(1.0, 1.8, 0.0))->normalize()->multiplyWith(11.25);
|
||||||
|
|
||||||
|
$canvas = new Canvas(900, 550);
|
||||||
|
$color = new Color(0.0, 1.0, 0.0);
|
||||||
|
|
||||||
while ($projectile->position->y() > 0) {
|
while ($projectile->position->y() > 0) {
|
||||||
echo $projectile->position->x() . ' | ' . $projectile->position->y() . PHP_EOL;
|
$canvas->addPixel((int)$projectile->position->x(), 550 - (int)$projectile->position->y(), $color);
|
||||||
tick($environment, $projectile);
|
tick($environment, $projectile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$adapter = new Local(__DIR__ . '/../images');
|
||||||
|
$filesystem = new Filesystem($adapter);
|
||||||
|
$canvasWriter = new CanvasPpmFileWriter($filesystem);
|
||||||
|
$canvasWriter->createFile($canvas, 'virtual_cannon.ppm');
|
||||||
Loading…
Reference in a new issue