Created
December 17, 2014 23:06
-
-
Save liamka/78cd0ae3732c71edb990 to your computer and use it in GitHub Desktop.
Olympus Has Fallen
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace ShowMadness; | |
ini_set('memory_limit', '-1'); | |
class ShowMadness | |
{ | |
var $currency_names = array('dollar', 'euro'); | |
var $MEGA_ARRAY = array(); | |
public function __construct(){ | |
// header | |
//header('Content-type: image/png'); | |
$this->GrabFiles(); // Grab files | |
$this->ParseFiles(); // Parse files | |
$this->CreateImage(); // Create images | |
} | |
// Grab data from files | |
public function GrabFiles() | |
{ | |
foreach ($this->currency_names as $currency_name) { | |
$this->MEGA_ARRAY[$currency_name] = file_get_contents('Assets/' . $currency_name . '.txt'); | |
} | |
} | |
public function ParseFiles() | |
{ | |
$lines = explode("\n",$this->MEGA_ARRAY['dollar']); // Dollar by default | |
$this->GetEachLine(); // Get each line | |
$this->MEGA_ARRAY['lines'] = $this->ManyLines($lines); | |
$this->UpperLover($lines); | |
} | |
public function ManyLines($lines) | |
{ | |
$count = count($lines); | |
return $count; | |
} | |
public function UpperLover($lines) | |
{ | |
foreach ($this->currency_names as $currency_name) { | |
array_shift($this->MEGA_ARRAY[$currency_name . '_lines']); | |
$this->MEGA_ARRAY[$currency_name . '_max'] = max($lines); | |
$this->MEGA_ARRAY[$currency_name . '_min'] = min($lines); | |
} | |
} | |
public function GetEachLine() | |
{ | |
foreach ($this->currency_names as $currency_name) { | |
$array_st = explode("\n",$this->MEGA_ARRAY[$currency_name]); | |
foreach ($array_st as $st) { | |
$this->MEGA_ARRAY[$currency_name . '_lines'][] = str_replace(',', '', $st); | |
} | |
} | |
} | |
public function CreateImage() | |
{ | |
foreach ($this->currency_names as $currency_name) { | |
$height_graf = ($this->MEGA_ARRAY[$currency_name . '_max'] - $this->MEGA_ARRAY[$currency_name . '_min']) + 30; | |
$height_graf_ = $height_graf/2; | |
$height_middle = explode('.', $height_graf_); | |
// Design | |
$this->MEGA_ARRAY[$currency_name . '_GRAF'] = imagecreate( $this->MEGA_ARRAY['lines'], $height_graf ); // width\height | |
$text_colour = imagecolorallocate( $this->MEGA_ARRAY[$currency_name . '_GRAF'], 255, 255, 0 ); | |
$dot = imagecolorallocate( $this->MEGA_ARRAY[$currency_name . '_GRAF'], 255, 255, 255 ); | |
// Set background | |
$background = imagecolorallocate($this->MEGA_ARRAY[$currency_name . '_GRAF'], 0, 0, 255); | |
imagefill($this->MEGA_ARRAY[$currency_name . '_GRAF'], 0, 0, $background); | |
$line_count = 0; | |
foreach ($this->MEGA_ARRAY[$currency_name . '_lines'] as $line) { | |
$line_ = $this->metrika($line,$currency_name,$line_count,$height_middle[0]); | |
//echo $line_ . "\n"; | |
imagesetpixel($this->MEGA_ARRAY[$currency_name . '_GRAF'], $line_count, $line_, $dot); // X\Y ширина\высота | |
$line_count++; | |
} | |
//var_dump($this->MEGA_ARRAY[$currency_name . '_lines']); | |
imagepng( $this->MEGA_ARRAY[$currency_name . '_GRAF'] ); | |
imagejpeg($this->MEGA_ARRAY[$currency_name . '_GRAF'], 'Assets/Grafs/' . $currency_name . '.jpg'); | |
imagedestroy( $this->MEGA_ARRAY[$currency_name . '_GRAF'] ); | |
} | |
} | |
public function metrika($line,$currency_name,$line_count,$height_middle) | |
{ | |
if($line_count == 0) { | |
} | |
if($line_count == 1) { | |
$this->zero = $line; | |
} | |
if($line == $this->zero) { | |
$difference = $height_middle; | |
} | |
if($line > $this->zero) { | |
if($this->zero == NULL) { | |
} else { | |
$difference = $line - $this->zero; | |
} | |
//var_dump($line); | |
//var_dump($this->zero); | |
} | |
if($line < $this->zero) { | |
$difference = $line - $this->zero; | |
} | |
return $difference; | |
} | |
} | |
new ShowMadness(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment