Skip to content

Instantly share code, notes, and snippets.

@BlackScorp
Created September 8, 2017 13:48
Show Gist options
  • Save BlackScorp/8414a5f435457aa13251fcdc5bd5cb5b to your computer and use it in GitHub Desktop.
Save BlackScorp/8414a5f435457aa13251fcdc5bd5cb5b to your computer and use it in GitHub Desktop.
<?php
$width = 800;
$height = 800;
$centerX = $width / 2;
$centerY = $height / 2;
$img = imagecreate($width, $height);
$backgroundColor = imagecolorallocate($img, 220, 220, 220);
$orange = imagecolorallocate($img, 255, 165, 0);
$black = imagecolorallocate($img, 0, 0, 0);
$violet = imagecolorallocate($img, 238, 130, 238);
$green = imagecolorallocate($img, 0, 128, 0);
$blue = imagecolorallocate($img, 0, 0, 128);
$drawSun = function () use (&$img, $centerX, $centerY, $orange, $violet, $black) {
imagefilledarc($img, $centerX, $centerY, 15, 15, 0, 360, $orange, IMG_ARC_PIE);
imagearc($img, $centerX, $centerY, 65, 65, 0, 360, $violet);
};
;
$drawPlanet = function ($orbit,$startGrid,$color) use (&$img, $centerX, $centerY, $black) {
$planetX = $centerX + sin(deg2rad($startGrid)) * 50 * $orbit;
$planetY = $centerY + cos(deg2rad($startGrid)) * 50 * $orbit;
imagearc($img, $centerX, $centerY, 50*$orbit, 50*$orbit, 0, 360, $black);
imagefilledarc($img, $planetX, $planetY, 8, 8, 0, 360, $color, IMG_ARC_PIE);
};
$drawBackground = function () use ($drawSun,$drawPlanet,$green) {
$drawSun();
$drawPlanet(2,350,$green);
};
$drawBackground();
header("Content-type: image/png");
imagepng($img);
imagedestroy($img);
die();
/**
* // Converts from degrees to radians.
* Math . radians = function (degrees) {
* return degrees * Math . PI / 180;
* };
*
* // Converts from radians to degrees.
* Math . degrees = function (radians) {
* return radians * 180 / Math . PI;
* };
*
* canvasWidth = $("canvas") . width();
* canvasHeight = $("canvas") . height();
*
* canvas = document . getElementById('canvas');
* context = canvas . getContext('2d');
*
* context . clearRect(0, 0, canvas . width, canvas . height);
*
* context . font = "12px Arial";
*
* centerX = canvasWidth / 2;
* centerY = canvasHeight / 2;
*
* drawWorld(0);
* drawBackground();
*
* // draw paths
* $("#tick") . change(function () {
* context . clearRect(0, 0, canvas . width, canvas . height);
* drawWorld($("#tick") . val());
* drawBackground();
* });
*
* function drawBackground()
* {
* //sun
* centerX = (canvasWidth / 2);
* centerY = (canvasWidth / 2);
* context . beginPath();
* context . arc(centerX, centerY, 10, 0, 2 * Math . PI, false);
* context . lineWidth = 5;
* context . fillStyle = 'orange';
* context . fill();
* context . strokeStyle = 'orange';
* context . stroke();
* context . fillStyle = 'black';
* context . fillText("Sonne", centerX + 10, centerY);
*
*
* //orbits
* for (orbit = 2; orbit < 7; orbit++)
* {
* for (grad = 0; grad < 360; grad++)
* {
* centerX = (canvasWidth / 2) + Math . sin(grad) * 50 * orbit;
* centerY = (canvasWidth / 2) + Math . cos(grad) * 50 * orbit;
* context . beginPath();
* context . arc(centerX, centerY, 1, 0, 2 * Math . PI, false);
* context . lineWidth = 1;
* context . fillStyle = 'black';
* context . fill();
* context . strokeStyle = 'black';
* context . stroke();
* }
* }
* //gravitation belt
* for (grad = 0; grad < 360; grad++)
* {
* centerX = (canvasWidth / 2) + Math . sin(grad) * 50 * 1;
* centerY = (canvasWidth / 2) + Math . cos(grad) * 50 * 1;
* context . beginPath();
* context . arc(centerX, centerY, 1, 0, 2 * Math . PI, false);
* context . lineWidth = 1;
* context . fillStyle = 'violet';
* context . fill();
* context . strokeStyle = 'violet';
* context . stroke();
* }
*
* startGrad = 230;
* startOrbit = 2;
* //start planet
* centerX = (canvasWidth / 2) + (Math . sin(Math . radians(startGrad)) * 50 * startOrbit);
* centerY = (canvasWidth / 2) + (Math . cos(Math . radians(startGrad)) * 50 * startOrbit);
* context . beginPath();
* context . arc(centerX, centerY, 3, 0, 2 * Math . PI, false);
* context . lineWidth = 5;
* context . fillStyle = 'green';
* context . fill();
* context . strokeStyle = 'green';
* context . stroke();
* context . fillStyle = 'black';
* context . fillText("Start Planet", centerX + 10, centerY);
* }
*
* function drawWorld(tick)
* {
*
* targetGrad = 0;
* targetOrbit = 6;
*
* // draw target
* centerX = (canvasWidth / 2) + (Math . sin(Math . radians(targetGrad + (tick * 0.25 / targetOrbit))) * 50 * targetOrbit);
* centerY = (canvasWidth / 2) + (Math . cos(Math . radians(targetGrad + (tick * 0.25 / targetOrbit))) * 50 * targetOrbit);
*
* context . beginPath();
* context . arc(centerX, centerY, 3, 0, 2 * Math . PI, false);
* context . lineWidth = 5;
* context . fillStyle = 'red';
* context . fill();
* context . strokeStyle = 'red';
* context . stroke();
* context . fillStyle = 'black';
* context . fillText("Ziel Planet", centerX + 10, centerY);
*
*
* planet2Grad = 129;
* planet2Orbit = 3;
*
* centerX = (canvasWidth / 2) + (Math . sin(Math . radians(planet2Grad + (tick * 0.25 / planet2Orbit))) * 50 * planet2Orbit);
* centerY = (canvasWidth / 2) + (Math . cos(Math . radians(planet2Grad + (tick * 0.25 / planet2Orbit))) * 50 * planet2Orbit);
*
* context . beginPath();
* context . arc(centerX, centerY, 3, 0, 2 * Math . PI, false);
* context . lineWidth = 5;
* context . fillStyle = 'blue';
* context . fill();
* context . strokeStyle = 'blue';
* context . stroke();
* context . fillStyle = 'black';
* context . fillText("Anderer Planet", centerX + 10, centerY);
*
*
* context . beginPath();
* context . arc(centerX, centerY, 25, 0, 2 * Math . PI, false);
* context . lineWidth = 1;
* context . fillStyle = 'blue';
* context . stroke();
* context . fillStyle = 'blue';
*
* planet3Grad = 340;
* planet3Orbit = 4;
*
* centerX = (canvasWidth / 2) + (Math . sin(Math . radians(planet3Grad + (tick * 0.25 / planet3Orbit))) * 50 * planet3Orbit);
* centerY = (canvasWidth / 2) + (Math . cos(Math . radians(planet3Grad + (tick * 0.25 / planet3Orbit))) * 50 * planet3Orbit);
*
* context . beginPath();
* context . arc(centerX, centerY, 3, 0, 2 * Math . PI, false);
* context . lineWidth = 5;
* context . fillStyle = 'blue';
* context . fill();
* context . strokeStyle = 'blue';
* context . stroke();
* context . fillStyle = 'black';
* context . fillText("Anderer Planet", centerX + 10, centerY);
*
*
* context . beginPath();
* context . arc(centerX, centerY, 25, 0, 2 * Math . PI, false);
* context . lineWidth = 1;
* context . fillStyle = 'blue';
* context . stroke();
* context . fillStyle = 'blue';
*
* planet4Grad = 340;
* planet4Orbit = 5;
*
* centerX = (canvasWidth / 2) + (Math . sin(Math . radians(planet4Grad + (tick * 0.25 / planet4Orbit))) * 50 * planet4Orbit);
* centerY = (canvasWidth / 2) + (Math . cos(Math . radians(planet4Grad + (tick * 0.25 / planet4Orbit))) * 50 * planet4Orbit);
*
* context . beginPath();
* context . arc(centerX, centerY, 3, 0, 2 * Math . PI, false);
* context . lineWidth = 5;
* context . fillStyle = 'blue';
* context . fill();
* context . strokeStyle = 'blue';
* context . stroke();
* context . fillStyle = 'black';
* context . fillText("Anderer Planet", centerX + 10, centerY);
*
*
* context . beginPath();
* context . arc(centerX, centerY, 25, 0, 2 * Math . PI, false);
* context . lineWidth = 1;
* context . fillStyle = 'blue';
* context . stroke();
* context . fillStyle = 'blue';
*
* }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment