eXorithm – Execute Algorithm: View / Run Algorithm sort_multi_array

function sort_multi_array ($array$key
{
  $keys = array();
  for ($i=1;$ifunc_num_args();$i++) {
    $keys$i-1] = func_get_arg$i);
  }
  
  // create a custom search function to pass to usort
  $func = function ($a$buse ($keys) {
    for ($i=0;$icount$keys);$i++) {
      if ($a$keys$i]] != $b$keys$i]]) {
        return ($a$keys$i]] < $b$keys$i]]) ? -1 : 1;
      }
    }
    return 0;
  };
  
  usort$array$func);
  
  return $array

Overlay Image

<?php

/**
 * overlay_image
 *
 * Overlay a transparent image on top of another image.
 *
 * @version 0.2
 * @author Contributors at eXorithm
 * @link /algorithm/view/overlay_image Listing at eXorithm
 * @link /algorithm/history/overlay_image History at eXorithm
 * @license /home/show/license
 *
 * @param resource $base (GD image) 
 * @param resource $image (GD image) 
 * @return mixed
 */
function overlay_image($base=null,$image=null)
{
	$h = imagesy($image);
	$w = imagesx($image);
	
	imagealphablending($base, true);
	imagesavealpha($base, true);
	imagecopy($base, $image, 0, 0, 0, 0, $w, $h);
	return $base;
}

?>

eXorithm – Execute Algorithm: View / Run Algorithm equilateral_shape

function equilateral_shape ($radius$sides$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 shape so a flat
  // line is at the bottom.
  if (($sides%2)==0) {
    if (($sides/2%2)==0) {
      $fudge = pi()*1/$sides
    } else {
      $fudge = 0;
    }
  } else {
    if ((($sides-1)/2%2)==0) {
      $fudge = pi()*1.5/$sides
    } else {
      $fudge = pi()*0.5/$sides
    }
  }
  
  $x0 = 0;
  $y0 = 0;
  
  // for the number of sides...
  for ($i=0; $i$sides$i++) {
    // compute a point on the perimeter $i/$sides from the beginning
    $x1 = round$radiuscos(2*pi()*$i$sides$fudge)+$radius+2);
    $y1 = round$radiussin(2*pi()*$i$sides$fudge)+$radius+2);
    if ($i==0) {
      // If this is the first point then we can't draw a line yet
      // because we don't have a second set of points to connect to.
      // However, we need we need these points to connect the last
      // set of points to.
      $x0 = $x1
      $y0 = $y1
    } else {
      // draw a line
      imageline$image$x1$y1$x2$y2$color);
    }
    // remember these points
    $x2 = $x1
    $y2 = $y1
  }
  // draw the final line
  imageline$image$x2$y2$x0$y0$color);
  
  return $image

eXorithm – Execute Algorithm: Embed Algorithm stock_ticker


Embed This Algorithm

This page will help you embed the algorithm stock_ticker on a page on your own website. Just configure the inputs, then click the generate button to get a snippet of code you can paste onto your site. You have two options.

  1. You can embed the entire form. Users will be able to enter their own arguments, and will need to press the run button to execute the algorithm.
  2. You can add only the output of the algorithm to your website. There will be no argument inputs or run button.

symbols
Argument info
background color Argument info
stock color Argument info
price color Argument info
up color Argument info
down color Argument info
speed Argument info
Embed the form Embed only the output

Unique Image

<?php

/**
 * unique_image
 *
 * Generate a pseudo-unique "hash" image based on a string.
 *
 * @version 0.3
 * @author Contributors at eXorithm
 * @link /algorithm/view/unique_image Listing at eXorithm
 * @link /algorithm/history/unique_image History at eXorithm
 * @license /home/show/license
 *
 * @param mixed $string 
 * @return resource GD image
 */
function unique_image($string='whatever')
{
	$size=200;
	$steps=5;
	$step=$size/$steps;
	
	$image = image_create_alpha($size, $size);
	
	$n = 0;
	$prev = 0;
	$len = strlen($string);
	$sum = 0;
	for ($i=0;$i<$len;$i++) $sum += ord($string[$i]);
	
	for ($i=0;$i<$steps;$i++) {
		for ($j=0;$j<$steps;$j++) {
			$letter = $string[$n++ % $len];
			
			$u = ($n % (ord($letter)+$sum)) + ($prev % (ord($letter)+$len)) + (($sum-1) % ord($letter));
			$color = imagecolorallocate($image, pow($u*$prev+$u+$prev+5,2)%256, pow($u*$prev+$u+$prev+3,2)%256, pow($u*$prev+$u+$prev+1,2)%256);
			if (($u%2)==0)
				imagefilledpolygon($image, array($i*$step, $j*$step, $i*$step+$step, $j*$step, $i*$step, $j*$step+$step), 3, $color);
			$prev = $u;
			
			$u = ($n % (ord($letter)+$len)) + ($prev % (ord($letter)+$sum)) + (($sum-1) % ord($letter));
			if (($u%2)==0)
				imagefilledpolygon($image, array($i*$step, $j*$step+$step, $i*$step+$step, $j*$step+$step, $i*$step+$step, $j*$step), 3, $color);
			$prev = $u;
		
		}
	}
	
	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;
}

?>

Simple Sort

<?php

/**
 * simple_sort
 *
 * Sort an array and display it.
 *
 * @version 0.1
 * @author Contributors at eXorithm
 * @link /algorithm/view/simple_sort Listing at eXorithm
 * @link /algorithm/history/simple_sort History at eXorithm
 * @license /home/show/license
 *
 * @param array $array 
 * @return array
 */
function simple_sort($array=array(0=>'1',1=>'11',2=>'22',3=>'3',4=>'4'))
{
	sort($array);
	return $array;
}

?>