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
}
Tag: Time
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 sum_list
function sum_list ($numbers
{
return array_sum$numbers);
}
eXorithm – Execute Algorithm: View / Run Algorithm validate_email
function validate_email ($email
{
if (preg_match"%^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$%i", $email))
return true;
else
return false;
}
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 volume_cone
function volume_cone ($radius, $height
{
  return (1/3) * pi() * ($radius$radius) * $height
}Â
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 sorted
function sorted ($array
{
$len = count$array);
for$i=1; $i$len; $i++) {
if$array$i-1] > $array$i])
return false;
}
return true;
}
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> "
$return .= "<span style="color:#$price_color">$lasttrade</span> "
if ($change<0)
$return .= "<span style="color:#$down_color">$change</span> "
else
$return .= "<span style="color:#$up_color">$change</span> "
$return .= " "
}
$return .= '</marque>
</div>'
return $return
}