eXorithm – Execute Algorithm: View / Run Algorithm number_string

function number_string ($number

{

  $names = array

    0=>"zero", 1=>"one", 2=>"two", 3=>"three", 4=>"four"

    5=>"five", 6=>"six", 7=>"seven", 8=>"eight", 9=>"nine"

    10=>"ten", 11=>"eleven", 12=>"twelve", 13=>"thirteen", 14=>"fourteen"

    15=>"fifteen", 16=>"sixteen", 17=>"seventeen", 18=>"eighteen", 19=>"nineteen"

    20=>"twenty", 30=>"thirty", 40=>"forty", 50=>"fifty"

    60=>"sixty", 70=>"seventy", 80=>"eighty", 90=>"ninety"

  );

  

  $triplets = array

    100=>"hundred"

    1000=>"thousand"

    1000000=>"million"

    1000000000=>"billion"

    1000000000000=>"trillion"

    1000000000000000=>"quadrillion"

    1000000000000000000=>"quintillion"

    1000000000000000000000=>"sextillion"

    1000000000000000000000000=>"septillion"

    1000000000000000000000000000=>"octillion"

    1000000000000000000000000000000=>"nonillion"

  );

  

  krsort$names);

  krsort$triplets);

  

  if (abs$number) > PHP_INT_MAX) 

    throw new Exception'Maximum integer size for this version of PHP is '.PHP_INT_MAX);

  

  $prefix = ''

  $str = ''

  if ($number<0) {

    $prefix = 'negative '

    $number = $number*-1;

  }

  

  $remainder = 0;

  

  if ($number>=100) {

    

    foreach ($triplets as $num=>$name) {

      if ($num<=$number) {

        $str = $name

        $remainder = $number % $num

        $number = floor$number$num);

        break

      }

    }

    

    // how many of the triplets?

    $str = number_string$number).' '$str

    

    if ($remainder<100) $separator = ' and '

    else $separator = ', '

    

  } else {

    

    foreach ($names as $num=>$name) {

      if ($num<=$number) {

        $str = $name

        $remainder = $number % $num

        break

      }

    }

    

    $separator = '-'

  }

  

  // remainder to tack on?

  if ($remainder>0) {

    $str = $str$separatornumber_string$remainder);

  }

  

  return $prefix$str

eXorithm – Execute Algorithm: View / Run Algorithm draw_bezier

function draw_bezier ($p0$p1$p2$p3$detail$show_bounds
{
  $x0$p0[0];$x1$p1[0];$x2$p2[0];$x3$p3[0];
  $y0$p0[1];$y1$p1[1];$y2$p2[1];$y3$p3[1];
  
  $cx=3*($x1$x0);
  $bx=3*($x2$x1)-$cx
  $ax$x3$x0$cx$bx
  
  $cy=3*($y1$y0);
  $by=3*($y2$y1)-$cy
  $ay$y3$y0$cy$by
  
  // generate the bezier points
  for$i=0; $i<=$detail$i++) {
    $t = $i$detail
    $x = $ax$t$t$t$bx$t$t$cx$t$x0
    $y = $ay$t$t$t$by$t$t$cy$t$y0
    $points$i] = array$x$y);
  }
  
  $width=400;
  $height=400;
  $imageimage_create_alpha$width$height);
  
  $cimagecolorallocate$image,0,0,0);
  $c2imagecolorallocate$image,200,200,200);
  
  // determine scale so curve shows within our image
  $minxmin$x0$x1$x2$x3);
  $maxxmax$x0$x1$x2$x3);
  $minymin$y0$y1$y2$y3);
  $maxymax$y0$y1$y2$y3);
  if ($maxx==$minx
    $scale = ($height-1)/($maxy$miny);
  else if ($maxy==$miny
    $scale = ($width-1)/($maxx$minx);
  else
    $scale = min(($width-1)/($maxx$minx), ($height-1)/($maxy$miny));
  
  if ($show_bounds) {
    imageline$image, ($x0$minx)*$scale, ($y0$miny)*$scale, ($x1$minx)*$scale, ($y1$miny)*$scale$c2);
    imageline$image, ($x1$minx)*$scale, ($y1$miny)*$scale, ($x2$minx)*$scale, ($y2$miny)*$scale$c2);
    imageline$image, ($x2$minx)*$scale, ($y2$miny)*$scale, ($x3$minx)*$scale, ($y3$miny)*$scale$c2);
  }
  
  // draw the bezier
  for ($i=1;$icount$points);$i++) {
    imageline$image, ($points$i-1][0]-$minx)*$scale, ($points$i-1][1]-$miny)*$scale, ($points$i][0]-$minx)*$scale, ($points$i][1]-$miny)*$scale$c);
  }
             
  return $image

eXorithm – Execute Algorithm: View / Run Algorithm locate_country

function locate_country ($country

{

  $data = file_get_contents"http://maps.google.com/maps/geo?output=csv&q="urlencode$country));

  $arr = explode","$data);

  if (count$arr)>=4) {

    if ($arr[0]==200) {

      return array'latitude'=>$arr[2], 'longitude'=>$arr[3]);

    } else {

      throw new Exception'Country could not be geocoded');

    }

  } else {

    throw new Exception'Country could not be geocoded');

  }

eXorithm – Execute Algorithm: View / Run Algorithm flip_image

function flip_image ($image$mode

{

  $width = imagesx$image);

  $height = imagesy$image);

  

  $src_x = 0;

  $src_y = 0;

  $src_width = $width

  $src_height = $height

  

  switch ( $mode ) {

      

    case 'vertical'//vertical

      $src_y      =   $height -1;

      $src_height =   -$height

      break

      

    case 'horizontal'//horizontal

      $src_x      =   $width -1;

      $src_width  =   -$width

      break

      

    case 'both'//both

      $src_x      =   $width -1;

      $src_y      =   $height -1;

      $src_width  =   -$width

      $src_height =   -$height

      break

      

    default

      return $image

  }

  

  $imgdest = imagecreatetruecolor$width$height);

  imagealphablending$imgdest, false);

  imagesavealpha$imgdest, true);

  

  if (imagecopyresampled$imgdest$image, 0, 0, $src_x$src_y , $width$height$src_width$src_height)) {

    return $imgdest

  }

  

  return $image