Feb 25, 2012

HTS Programming Mission 4


If you are copy-pasting this thing and thinking that getting points will make you more cool amongst your friends then you can just fuck off. You will remain dumb then. You can understand the algorithm I used and implement in your own way

Here what I have done is I created a php script that analyzes your downloaded “xml” data and show you the encoded text.

You need a active webserver .You can also run an offline local host using softwares like phpmyadmin or etc.

The xml file must be named ‘plotMe.xml’ and must be present in the same directory where this php program stays.

You can send me you algorithm for review and your ideas to share in this post.

<?php
ini_set
('error_reporting', E_ALL);ini_set('display_errors', 'On');ini_set('display_startup_errors', 'On');

 $file='plotMe.xml'; // xml filename


//
 there is nothing below that you really need to edit
$fh=fopen($file,'r') or die("Couldn't open the file");$xml=fread($fh,filesize($file));fclose($fh);
$w=750; // image width$h=750; // image height
$im=imagecreatetruecolor($w,$h);imageantialias($im,true);
$d=new DOMDocument();
if(
$d->loadXML($xml)){
    $lines=arr($d->getElementsByTagName('Line'));
    $arcs=arr($d->getElementsByTagName('Arc'));
    foreach($lines as $line){
        imageline($im,
            $line['XStart'],
            $h-$line['YStart'],
            $line['XEnd'],
            $h-$line['YEnd'],
            color((!isset($line['Color']))?null:$line['Color'])
        );
    }
    foreach($arcs as $arc){
        $len=$arc['Radius']*2;
        imagearc($im,
            $arc['XCenter'],
            $h-$arc['YCenter'],
            $len,
            -$len,
            $arc['ArcStart'],
            $arc['ArcStart']+$arc['ArcExtend'],
            color((!isset($arc['Color']))?null:$arc['Color'])
        );
    }
}
 else die("WTF? Couldn't loadXML()..");
header('Content-Type: image/png');imagepng($im);

function
 arr($os){
    foreach($os as $o){
        $tmp=array();
        if($o->childNodes->length){
            foreach($o->childNodes as $node){
                $tmp[$node->nodeName]=$node->nodeValue;
            }
        }
        $ret[]=$tmp;
    }
    return $ret;
}
function
 color($c){
    switch($c){
        case 'blue':
            return 255;
        case 'green':
            return 65280;
        case 'red':
            return 16711680;
        case 'yellow':
            return 16776960;
        default:
            return 16777215;
    }
}
?> 


No comments:

Post a Comment