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: History For Algorithm show_address

show_address ย ย ย  version 0.6 ย ย ย  Given an address, show the location on a map.
Version Note Created Diff
0.6 [edit fix for new API Mar 11, 2013 09:09 am by Mike Campbell
0.5 [revert Dec 1, 2012 12:39 am by Mike Campbell
0.4 [revert Nov 28, 2012 06:41 am by harrison7042
0.3 [revert Nov 28, 2012 06:41 am by harrison7042
0.2 [revert Oct 3, 2010 11:52 pm by Mike Campbell
0.1 [revert Sep 28, 2010 05:10 pm by Mike Campbell

eXorithm – Execute Algorithm: View / Run Algorithm invert_image

function invert_image ($image
{
  $image_width = imagesx$image);
  $image_height = imagesy$image);
  
  // if the image is not true color, make it so
  if (!imageistruecolor$image)) {
    $image2 = imagecreatetruecolor$image_width$image_height);
    imagecopy$image2$image,0,0,0,0,$image_width$image_height);
    $image = $image2
  }
  
  // loop through all the pixels
  for ($h = 0; $h < $image_height$h++) {
    for ($w = 0; $w < $image_width$w++) {
      // get the color at this pixel
      $color = imagecolorsforindex$imageimagecolorat$image$w$h));
      // invert the color
      $color'red'] = 255 - $color'red'];
      $color'green'] = 255 - $color'green'];
      $color'blue'] = 255 - $color'blue'];
      // create the new color
      $new_color = imagecolorallocate$image$color'red'], $color'green'], $color'blue']);
      // set the color
      imagesetpixel$image$w$h$new_color);
    }
  }
  
  return $image

eXorithm – Execute Algorithm: View / Run Algorithm html_select

function html_select ($name$items$selected$use_keys
{
  $html = "<select name="$name">n"
  foreach ($items as $key=>$value) {
    if (!$use_keys$key = $value
    if ($selected == $key
      $s = ' selected'
    else
      $s = ''
    $html .= "<option value=""$key""$s>"$value"</option>n"
  }
  $html .= "</select>"
  return $html

Draw UPC Barcode

<?php

/**
 * draw_upc_barcode
 *
 * Draw a barcode for a UPC number.
 *
 * @version 0.3
 * @author Contributors at eXorithm
 * @link /algorithm/view/draw_upc_barcode Listing at eXorithm
 * @link /algorithm/history/draw_upc_barcode History at eXorithm
 * @license /home/show/license
 *
 * @param mixed $number The 12-digit UPC number.
 * @param bool $show_numbers Whether to draw the numbers at the bottom of the barcode.
 * @return resource GD image
 */
function draw_upc_barcode($number='925853043217',$show_numbers=true)
{
	$number = str_replace(array('-',' '), '', $number);
	
	if (strlen($number)!=12)
		throw new Exception("UPC number must have 12 digits");
	
	for ($i=0;$i<12;$i++) {
		if (!is_numeric($number[$i]))
			throw new Exception("UPC number must contain only digits");
	}
	
	$lcodes = array(
		'0001101',
		'0011001',
		'0010011',
		'0111101',
		'0100011',
		'0110001',
		'0101111',
		'0111011',
		'0110111',
		'0001011',
	);
	
	$rcodes = array(
		'1110010',
		'1100110',
		'1101100',
		'1000010',
		'1011100',
		'1001110',
		'1010000',
		'1000100',
		'1001000',
		'1110100',
	);
	
	$code = '101';
	for ($i=0;$i<6;$i++) {
		$code .= $lcodes[$number[$i]];
	}
	$code .= '01010';
	for ($i=6;$i<12;$i++) {
		$code .= $rcodes[$number[$i]];
	}
	$code .= '101';
	
	// create image
	$width=190;
	$height=100;
	$image = image_create_alpha($width, $height);
	
	$white = imagecolorallocate($image, 255, 255, 255);
	imagefilledrectangle($image, 0, 0, $width, $height, $white);
	
	// draw lines
	$black = imagecolorallocate($image, 0, 0, 0);
	for ($i=0;$i<strlen($code);$i++) {
		if ($code[$i]=='1') {
			imageline($image, $i*2,0, $i*2, $height, $black);
			imageline($image, $i*2+1,0, $i*2+1, $height, $black);
		}
	}
	
	// draw numbers
	if ($show_numbers) {
		imagefilledrectangle($image, 6, $height-16, 90, $height, $white);
		imagefilledrectangle($image, 98, $height-16, 182, $height, $white);
		for ($i=0;$i<6;$i++) {
			imagestring($image, 2, 11+$i*14, $height-14, $number[$i], $black);
		}
		for ($i=6;$i<12;$i++) {
			imagestring($image, 2, 19+$i*14, $height-14, $number[$i], $black);
		}
	}
	
	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 surface_oblate_spheroid

function surface_oblate_spheroid ($polar_radius$equatorial_radius
{
  $x = acos( $polar_radius / $equatorial_radius );
  $e2 = $equatorial_radius * $equatorial_radius
  $p2 = $polar_radius * $polar_radius
  $abx = $polar_radius * $equatorial_radius * $x
  $area = 2 * pi() * ( ($e2) + ($p2 / sin$x)) * log((1+sin$x))/cos$x)) );
  return $area
}Â