eXorithm – Execute Algorithm: View / Run Algorithm star_polygon

function star_polygon ($radius$points$skip$color
{
  // blank image
  $image = image_create_alpha$radius*2+4, $radius*2+4);
  
  // create the color
  $r  = hexdecsubstr$color, 0, 2));
  $g  = hexdecsubstr$color, 2, 2));
  $b  = hexdecsubstr$color, 4, 2));
  $color = imagecolorallocate$image$r$g$b);
  
  // The fudge factor is only used to rotate the star so its points line
  // up at the bottom.
  if (($points%2)==0) {
    if (($points/2%2)==0) {
      $fudge = pi()*1/$points
    } else {
      $fudge = 0;
    }
  } else {
    if ((($points-1)/2%2)==0) {
      $fudge = pi()*1.5/$points
    } else {
      $fudge = pi()*0.5/$points
    }
  }
  
  $xy = array();
  
  // for the number of points...
  for ($i=0; $i$points$i++) {
    // compute a point on the perimeter $i/$points from the beginning
    $x = round$radiuscos(2*pi()*$i$points$fudge)+$radius+2);
    $y = round$radiussin(2*pi()*$i$points$fudge)+$radius+2);
    $xy[]=array$x$y);
  }
  
  for ($from=0; $fromcount$xy); $from++) {
    
    // where to draw the line to
    $to = ($from$skip+1) % (count$xy));
    
    // draw the line
    imageline$image$xy$from][0], $xy$from][1], $xy$to][0], $xy$to][1], $color);
  }
  
  return $image

eXorithm – Execute Algorithm: View / Run Algorithm project_polygon

function project_polygon ($points, $degree_x, $degree_y, $degree_z, $center_x, $center_y, $center_z, $dist1, $dist2, $include_z

{

  // check points

  if ((count$points)%3)!=0) {

    throw new Exception'The points must be a list like x1, y1, z1, x2, y2, z2, etc. The number of points therefore must be divisible by three.');

  }

  

  $degree_x = deg2rad$degree_x);

  $degree_y = deg2rad$degree_y);

  $degree_z = deg2rad$degree_z);

  

  $cosx = cos$degree_x);

  $sinx = sin$degree_x);

  $cosy = cos$degree_y);

  $siny = sin$degree_y);

  $cosz = cos$degree_z);

  $sinz = sin$degree_z);

  

  $array = array();

  

  for ($i=0;$icount$points);$i$i+3) {

    $x0 = $points$i]-$center_x

    $y0 = $points$i+1]-$center_y

    $z0 = $points$i+2]-$center_z

    

    $x1 = $cosy*($sinz$y0 + $cosz$x0) - $siny$z0

    $y1 = $sinx*($cosy$z0 + $siny*($sinz$y0 + $cosz$x0)) + $cosx*($cosz$y0 - $sinz$x0);

    $z1 = $cosx*($cosy$z0 + $siny*($sinz$y0 + $cosz$x0)) - $sinx*($cosz$y0 - $sinz$x0);

  

    $x2 = $x1$dist1/($z1$dist1$dist2);

    $y2 = $y1$dist1/($z1$dist1$dist2);

    $z2 = $z1$dist1/($z1$dist1$dist2);

  

    $array[] = $x2

    $array[] = $y2

    if ($include_z) $array[] = $z2

  }

  

  return $array

} 

eXorithm – Execute Algorithm: View / Run Algorithm xithm_world_stats_population

function xithm_world_stats_population ($country_list

{

  $connectionmysql_connect"xithmdb.aktiv.com""duppie""exorithm");

  $y = array();

  if$connection) {

    $db=@mysql_select_db"xithm"$connection);

    

    $sql = "select * from country_population"

    ifis_array$country_list)){

      ifcount$country_list) > 0) {

        $sql .= " where country in ("

        for ($ii=0; $iicount$country_list); $ii++) {

          $sql .= "'"mysql_real_escape_string$country_list$ii])."',"

        }

        $sql .= "'')"

      }

    }

    $mysql_result=@mysql_query$sql$connection);

    while ($rowmysql_fetch_array$mysql_result)) {

      $y$row[0]] = $row[1];

    }

    @mysql_close$connection);

  } else {

    throw new Exception"Could not connect.");

  }

  return $y

eXorithm – Execute Algorithm: View / Run Algorithm weather_forecast

function weather_forecast ($location$units$header_color$day_header_color$day_color

{

  $weather = file_get_contents'http://www.google.com/ig/api?weather='urlencode$location));

  

  $xml = simplexml_load_string$weather);

  

  if (!isset$xml->weather->forecast_conditions)) {

    throw new Exception'Data could not be retreived for location '$location);

  }

  

  $location = $xml->weather->forecast_information->city['data'];

                                                      

  // four day outlook

  for ($i = 0; $i < 4; $i++){

    if ($xml->weather->forecast_conditions->$i) {

      $forecast_day[] = $xml->weather->forecast_conditions->$i->day_of_week['data'];

      $forecast_condition[] = $xml->weather->forecast_conditions->$i->condition['data'];

      $low = $xml->weather->forecast_conditions->$i->low['data'];

      if ($units=='k'

        $low = round((($low - 32)*5/9) + 273, 1);

      else if ($units=='c'

        $low = round(($low - 32)*5/9, 1);

      $forecast_low[] = $low

      $high = $xml->weather->forecast_conditions->$i->high['data'];

      if ($units=='k'

        $high = round((($high - 32)*5/9) + 273, 1);

      else if ($units=='c'

        $high = round(($high - 32)*5/9, 1);

      $forecast_high[] = $high

      $forecast_icon[] = $xml->weather->forecast_conditions->$i->icon['data'];

    }

  }

  

  // current

  $condition = $xml->weather->current_conditions->condition['data'];

  $temp = $xml->weather->current_conditions->temp_f['data'];

  if ($units=='k'

    $temp = round((($temp - 32)*5/9) + 273, 1);

  else if ($units=='c'

    $temp = round(($temp - 32)*5/9, 1);

  $icon = $xml->weather->current_conditions->icon['data'];

  

  // build the HTML

  $header = "<tr><td colspan=""count$forecast_day)."" bgcolor="#$header_color">"

  if ($icon!=''

    $header .= "<img align="left" src="http://www.google.com$icon">"

  $header .= "<b>$location</b><br>Currently <i>$condition</i> <b>$temp$units</b>"

  $header .= "</td></tr>n<tr>"

  $data = "<tr>n"

  

  for ($i = 0; $i < count$forecast_day); $i++){

    $header .= "<td width="130" bgcolor="#$day_header_color"><b>$forecast_day[$i]</b></td>"

    $data .= "<td bgcolor="#$day_color">"

    $data .= "<img src="http://www.google.com$forecast_icon[$i]">"

    $data .= "<br><i>$forecast_condition[$i]</i>"

    $data .= "<br>high <b>$forecast_high[$i]$units</b>"

    $data .= "<br>low <b>$forecast_low[$i]$units</b>"

    $data .= "</td>n"

  }

  

  $header .= "</tr>"

  $data .= "</tr>"

  

  return "<table cellpadding="5" cellspacing="3">n$headern$datan</table>"

eXorithm – Execute Algorithm: View / Run Algorithm validate_url

function validate_url ($url

{

  $regex = '/^(https?|ftp)://'//protocol

  $regex .= '(([a-z0-9$_.+!*'(),;?&=-]|%[0-9a-f]{2})+'//username

  $regex .= '(:([a-z0-9$_.+!*'(),;?&=-]|%[0-9a-f]{2})+)?'//password

  $regex .= '@)?'//auth requires @

  $regex .= '((([a-z0-9][a-z0-9-]*[a-z0-9].)*'//domain segments AND

  $regex .= '[a-z][a-z0-9-]*[a-z0-9]'//top level domain  OR

  $regex .= '|((d|[1-9]d|1d{2}|2[0-4][0-9]|25[0-5]).){3}'

  $regex .= '(d|[1-9]d|1d{2}|2[0-4][0-9]|25[0-5])'//IP address

  $regex .= ')(:d+)?'//port

  $regex .= ')(((/+([a-z0-9$_.+!*'(),;:@&=-]|%[0-9a-f]{2})*)*'//path

  $regex .= '(?([a-z0-9$_.+!*'(),;:@&=-]|%[0-9a-f]{2})*)'//query string

  $regex .= '?)?)?'//path and query string optional

  $regex .= '(#([a-z0-9$_.+!*'(),;:@&=-]|%[0-9a-f]{2})*)?'//fragment

  $regex .= '$/i'

  

  return (preg_match$regex$url) ? true : false);

eXorithm – Execute Algorithm: View / Run Algorithm stock_ticker

function stock_ticker ($symbols$background_color$stock_color$price_color$up_color$down_color$speed
{
  sort$symbols);
  
  if ($background_color==$stock_color) {
    // something's wrong, colors weren't specified
    $background_color = invert_color$background_color);
  }
  
  $return = '<div align="center">
  <marquee bgcolor="#'$background_color'" loop="20" scrollamount="'$speed'">'
  
  foreach ($symbols as $symbol) {
    $data = file_get_contents"http://quote.yahoo.com/d/quotes.csv?s=$symbol&f=sl1d1t1c1ohgv&e=.csv");
    
    $values = explode","$data);
    $lasttrade = $values[1];
    $change = $values[4];
    
    $return .= "<span style="color:#$stock_color">$symbol</span> &nbsp;"
    $return .= "<span style="color:#$price_color">$lasttrade</span> &nbsp;"
    if ($change<0)
      $return .= "<span style="color:#$down_color">$change</span> &nbsp;"
    else
      $return .= "<span style="color:#$up_color">$change</span> &nbsp;"
    $return .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
  }
  
  $return .= '</marque>
  </div>'
  
  return $return