eXorithm – Execute Algorithm: View / Run Algorithm address_elevation

function address_elevation ($address
{
  // get the lat/long for this address
  $data = file_get_contents"http://maps.google.com/maps/geo?output=csv&q="urlencode$address));
  $arr = explode","$data);
  if (count$arr)>=4) {
    if ($arr[0]==200) {
      // get the elevation for this lat/long
      $data = file_get_contents"http://maps.googleapis.com/maps/api/elevation/xml?sensor=false&locations="$arr[2].','$arr[3]);
      $obj = simplexml_load_string$data);
      if ($obj instanceof SimpleXMLElement) {
        $obj = (array) $obj
        $obj = $obj'result'];
        if ($obj instanceof SimpleXMLElement) {
          $obj = (array) $obj
          return $obj'elevation'];
        } else {
          throw new Exception'Elevation lookup failed');
        }
      } else {
        throw new Exception'Elevation lookup failed');
      }
    } else {
      throw new Exception'Address lookup failed');
    }
  } else {
    throw new Exception'Address lookup failed');
  }

eXorithm – Execute Algorithm: History For Algorithm duotone_image

duotone_image     version 0.5     Change an image into a tinted grayscale.
Version Note Created Diff
0.5 [edit Jul 28, 2012 01:18 pm by ToneDJ
0.4 [revert Jul 28, 2012 01:16 pm by ToneDJ
0.3 [revert add percentage Nov 23, 2010 12:06 pm by Mike Campbell
0.2 [revert Nov 23, 2010 09:00 am by Mike Campbell
0.1 [revert Nov 23, 2010 08:50 am by Mike Campbell

Draw Triangle

<?php

/**
 * draw_triangle
 *
 * Draw a filled triangle.
 *
 * @version 0.4
 * @author Contributors at eXorithm
 * @link /algorithm/view/draw_triangle Listing at eXorithm
 * @link /algorithm/history/draw_triangle History at eXorithm
 * @license /home/show/license
 *
 * @param array $points This should be a list of six numbers that define the points of the triange (x1, y1, x2, y2, x3, y3)
 * @param string $color (hex color code) The color of the triangle
 * @return resource GD image
 */
function draw_triangle($points=array(0=>'0',1=>'0',2=>'0',3=>'8',4=>'8',5=>'4'),$color='000000')
{
	if (count($points)!=6) {
		throw new Exception('The points must be an array of 6 integers.');
	}
	
	$image = image_create_alpha(max($points[0], $points[2], $points[4])+1, max($points[1], $points[3], $points[5])+1);
	
	$red = hexdec(substr($color, 0, 2));
	$green  = hexdec(substr($color, 2, 2));
	$blue  = hexdec(substr($color, 4, 2));
		
	$color = imagecolorallocatealpha($image, $red, $green, $blue, 0);
	
	imagefilledpolygon($image, $points, 3, $color);
	
	return $image;
}

/**
 * image_create_alpha
 *
 * Helper function to create a new blank image with transparency.
 *
 * @version 0.1
 * @author Contributors at eXorithm
 * @link /algorithm/view/image_create_alpha Listing at eXorithm
 * @link /algorithm/history/image_create_alpha History at eXorithm
 * @license /home/show/license
 *
 * @param mixed $width 
 * @param mixed $height 
 * @return resource GD image
 */
function image_create_alpha($width='',$height='')
{
	// Create a normal image and apply required settings
	$img = imagecreatetruecolor($width, $height);
	imagealphablending($img, false);
	imagesavealpha($img, true);
	
	// Apply the transparent background
	$trans = imagecolorallocatealpha($img, 0, 0, 0, 127);
	for ($x = 0; $x < $width; $x++)
	{
		for ($y = 0; $y < $height; $y++)
		{
			imagesetpixel($img, $x, $y, $trans);
		}
	}
	
	return $img;
}

?>

eXorithm – Execute Algorithm: View / Run Algorithm biological_classification

function biological_classification ($lifeform
{
  // construct the query
  $query = array'name'=>$lifeform
                 'type'=>'/biology/organism_classification'
                 'higher_classification'=>null,
                 'rank'=>null, 
                 'scientific_name'=>null
                );
  
  
  // issue the query
  $results = freebase_query$query);
  
  if (isset$results[0])) {
   
    if (isset$results[0]['name']))
        $lifeform = $results[0]['name'];
    $return = "$lifeformnn"
  
    do {
      $rank = '(unranked)'
      $higher = ''
      $scientific = ''
      if (isset$results[0]['higher_classification']))
        $higher = $results[0]['higher_classification'];
      if (isset$results[0]['scientific_name']))
        $scientific = $results[0]['scientific_name'];
      if (isset$results[0]['rank']))
        $rank = $results[0]['rank'];
      
      // scientific name found
      if ($scientific != '') {
        $return .= "$rank: $scientificn"
      } else {
        $return .= "no informationn"
      }
      
      // higher lifeform found
      if ($higher != '') {
        $query'name'] = $higher
        $results = freebase_query$query);
      }
      
    } while ($higher != '');
    
    return $return
  } else {
    throw new Exception"Lifeform $lifeform not found");
  }

eXorithm – Execute Algorithm: View / Run Algorithm draw_sphere

function draw_sphere ($image_size$degree_x$degree_y$degree_z$vdist$dist$vertex_color$face_color$wireframe$dashes$sphere_detail
{
  $lats = 2*$sphere_detail+1; // latitudes, including equator and poles (should be odd)
  $longs = $sphere_detail*4;
  $degree_per_lat = 90/floor$lats/2);
  $degree_per_long = 360/$longs
  $radius = 200; // radius is arbitary
  
  // build all the polygons that make up a sphere
  for ($i=0;$iceil$lats/2);$i++) {
    $y = $radius * cosdeg2rad$degree_per_lat$i));
    $inner_radius = $radius * sindeg2rad$degree_per_lat$i));
    
    for ($j=0;$j$longs$j++) {
      $x = $inner_radius * sindeg2rad$degree_per_long$j));
      $z = $inner_radius * cosdeg2rad$degree_per_long$j));
      
      if ($iceil$lats/2)-1) {
        $poly = $i$longs$j+1;
        $sides$poly][6] = $x
        $sides$poly][7] = $y
        $sides$poly][8] = $z
        $sides$poly*-1][6] = $x
        $sides$poly*-1][7] = $y*-1;
        $sides$poly*-1][8] = $z
        
        if ($i>0) {
          $poly = $i$longs+(($j$longs-1) % $longs)+1;
          $sides$poly][9] = $x
          $sides$poly][10] = $y
          $sides$poly][11] = $z
          $sides$poly*-1][9] = $x
          $sides$poly*-1][10] = $y*-1;
          $sides$poly*-1][11] = $z
        }
      }
      
      if ($i>0) {
        $poly = ($i-1)*$longs$j+1;
        $sides$poly][3] = $x
        $sides$poly][4] = $y
        $sides$poly][5] = $z
        $sides$poly*-1][3] = $x
        $sides$poly*-1][4] = $y*-1;
        $sides$poly*-1][5] = $z
        
        $poly = ($i-1)*$longs+(($j$longs-1) % $longs)+1;
        $sides$poly][0] = $x
        $sides$poly][1] = $y
        $sides$poly][2] = $z
        $sides$poly*-1][0] = $x
        $sides$poly*-1][1] = $y*-1;
        $sides$poly*-1][2] = $z;           
      }
    }
    
  }
  
  $sides = array_values$sides);
  
  // project each of the polygons
  for ($i=0; $icount$sides); $i++) {
    $points[] = project_polygon$sides$i], $degree_x$degree_y$degree_z, 0, 0, 0, $vdist$radius$dist$radius, true);
  }
  
  // scale the image somewhat
  $scale = $image_size/($radius*2.2);
  
  return render_polygons$points$vertex_color$face_color$wireframe$dashes$image_size$scale);