function draw_mandelbrot ($width
{
$widthround$width);
$heightround$width*2/3.5);
// create image
$image = image_create_alpha$width, $height);
$max_iteration = 100;
// color pallet
$colorsarray();
for ($i=0;$i$max_iteration$i++) {
$shade = 60+round$i$max_iteration*195);
$colors$i] = imagecolorallocate$image, $shade, $shade, $shade);
}
// the "inside" color
$colors$max_iteration] = imagecolorallocate$image, 0, 0, 0);
// loop through all the pixels
for ($h = 0; $h < $height; $h++) {
for ($w = 0; $w < $width; $w++) {
// normalize the location of the pixel
$x0 = (3.5 * $w / $width)-2.5; // between -2.5 and 1
$y0 = (2 * $h / $height)-1; // between -1 and 1
$x = 0;
$y = 0;
$iteration = 0;
// the calculation
while ( ($x$x + $y$y <= (2*2)) && ($iteration < $max_iteration) ) {
$xtemp = $x$x - $y$y + $x0
$y = 2*$x$y + $y0
$x = $xtemp
$iteration = $iteration + 1;
}
// set color
imagesetpixel$image, $w, $h, $colors$iteration]);
}
}
return $image
}
Author: ToneDJCampbell
eXorithm – Execute Algorithm: View / Run Algorithm pie_chart
function pie_chart ($data
{
$size=200;
$centerx = 100;
$centery = 100;
$circle_diameter = 180;
$image = image_create_alpha$size, $size);
$blackimagecolorallocatealpha$image, 0, 0, 0, 0);
$total = array_sum$data);
$n = 0;
$start = 0;
foreach ($data as $key => $value) {
$length = 360 * $value$total
$color = allocate_color$image, generate_graph_color$n++));
imagefilledarc$image, $centerx, $centery, $circle_diameter, $circle_diameter, round$start), round$start$length), $color, IMG_ARC_PIE);
$start += $length
}
imageellipse$image, $centerx, $centery, $circle_diameter, $circle_diameter, $black);
return $image
}
eXorithm – Execute Algorithm: View / Run Algorithm moon_cycle
function moon_cycle ($date
{
$d = getdate$date);
$year = $d'year'];
$month = $d'mon'];
$day = $d'mday'];
$r = $year % 100;
$r %= 19;
if ($r>9)
$r -= 19;
$r = (($r * 11) % 30) + $month + $day
if ($month<3)
$r += 2;
$r -= (($year<2000) ? 4 : 8.3);
$r = floor$r+0.5)%30;
return ($r < 0) ? $r+30 : $r
}
eXorithm – Execute Algorithm: View / Run Algorithm rotate_image_alpha
function rotate_image_alpha ($image, $angle, $bgcolor, $bgtransparency
{
// seen at http://www.php.net/manual/en/function.imagerotate.php
$srcw = imagesx$image);
$srch = imagesy$image);
//Normalize angle
$angle %= 360;
//Set rotate to clockwise
$angle = -$angle
if$angle == 0) {
return $image
}
// Convert the angle to radians
$theta = deg2rad ($angle);
// Standard case of rotate
if ( (abs$angle) == 90) || (abs$angle) == 270) ) {
$width = $srch
$height = $srcw
if ( ($angle == 90) || ($angle == -270) ) {
$minX = 0;
$maxX = $width
$minY = -$height+1;
$maxY = 1;
$sin = 1;
} else if ( ($angle == -90) || ($angle == 270) ) {
$minX = -$width+1;
$maxX = 1;
$minY = 0;
$maxY = $height
$sin = -1;
}
$cos = 0;
} else if (abs$angle) === 180) {
$width = $srcw
$height = $srch
$minX = -$width+1;
$maxX = 1;
$minY = -$height+1;
$maxY = 1;
$sin = 0;
$cos = -1;
} else {
$sin = sin$theta);
$cos = cos$theta);
// Calculate the width of the destination image.
$temp = array (0,
$srcw * $cos
$srch * $sin
$srcw * $cos + $srch * $sin
);
$minX = floormin$temp));
$maxX = ceilmax$temp));
$width = $maxX - $minX
// Calculate the height of the destination image.
$temp = array (0,
$srcw * $sin * -1,
$srch * $cos
$srcw * $sin * -1 + $srch * $cos
);
$minY = floormin$temp));
$maxY = ceilmax$temp));
$height = $maxY - $minY
}
$destimg = imagecreatetruecolor$width, $height);
$bgcolor = allocate_color$destimg, $bgcolor, $bgtransparency);
imagefill$destimg, 0, 0, $bgcolor);
imagesavealpha$destimg, true);
// sets all pixels in the new image
for$x$minX; $x$maxX; $x++) {
for$y$minY; $y$maxY; $y++) {
// fetch corresponding pixel from the source image
$srcX = round$x * $cos - $y * $sin);
$srcY = round$x * $sin + $y * $cos);
if$srcX >= 0 && $srcX < $srcw && $srcY >= 0 && $srcY < $srch) {
$color = imagecolorat$image, $srcX, $srcY);
} else {
$color = $bgcolor
}
imagesetpixel$destimg, $x$minX, $y$minY, $color);
}
}
return $destimg
}
eXorithm – Execute Algorithm: View / Run Algorithm simple_choice
function simple_choice ($choice1, $choice2
{
return $choice1" on "$choice2", mmmm..."
}
eXorithm – Execute Algorithm: View / Run Algorithm part_of_speech
function part_of_speech ($word
{
  $data = file_get_contents"http://www.google.com/dictionary/json?callback=dict_api.callbacks.id100&q="urlencode$word)."&sl=en&tl=en&restrict=pr%2Cde&client=te");
 Â
  if ( (substr$data, 0, 25)=="dict_api.callbacks.id100(") &&
       (substr$data, -10)==",200,null)") )
  {
    $data = substr$data, 25, -10);
    $data = str_replace'x22', '"', $data);
    $data = decode_phpstring$data);
   Â
    $parts = array();
   Â
    $obj = json_decode$data);
   Â
    if (isset$obj->primaries)) {
      foreach ($obj->primaries as $prim) {
        $headword = ''
        $part = ''
        foreach ($prim->terms as $term) {
          if ($term->type=="text") {
            $headword = str_replace'·', '', $term->text);
            foreach ($term->labels as $label) {
              if ($label->title=="Part-of-speech") {
               Â
                $st = false;
                $part = strtolower$label->text);
               Â
                foreach ($prim->entries as $entry) {
                  if ($entry->type=="related") {
                    foreach ($entry->terms as $term2) {
                      if ($term2->text==$word) {
                        $st = true;
                        $i = count$parts);
                        $parts$i]['type'] = $part
                        $parts$i]['base'] = $headword
                        $parts$i]['subtype'] = $term2->labels[0]->text;
                      }
                    }
                  }
                }
               Â
                if (!$st) {
                  $i = count$parts);
                  $parts$i]['type'] = $part
                  $parts$i]['base'] = $headword
                  $parts$i]['subtype'] = ''
                }
              }
            }
          }
        }
      }
    }
    return $parts
   Â
  } else {
    throw new Exception"Google dictionary API did not return a result.");
  }
}Â
eXorithm – Execute Algorithm: History For Algorithm unity
unity    version 1.2    Returns digit summation of any numerical value given for passkey (up to 14 digits in length)
eXorithm – Execute Algorithm: View / Run Algorithm gcd_euclid
function gcd_euclid ($a, $b
{
  $a = abs$a);
  $b = abs$b);
 Â
  if ($a == 0)
    return $b
  elseif ($b == 0)
    return $a
  elseif ($a > $b
    return gcd_euclid$b, $a % $b);
  else
    return gcd_euclid$a, $b % $a);
}Â
eXorithm – Execute Algorithm: Embed Algorithm sort_multi_array
Embed This Algorithm
This page will help you embed the algorithm sort_multi_array 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.
- 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.
- You can add only the output of the algorithm to your website. There will be no argument inputs or run button.
eXorithm – Execute Algorithm: View / Run Algorithm array_fusion
function array_fusion ($array, $type
{
switch$type) {
case 'standard'
case 'positive'
return array_sum$array);
break
case 'negative'
return -array_sum$array);
break
case 'string'
return json_encodearray_sum$array));
break
case 'duplicate'
return powarray_sum$array), array_sum$array));
break
case 'del'
$return = $array
for$i = 0; $i < count$array); $i++)
if$i % 2 == 0 || $i * 3 == count$array))
unset$return$i]);
return array_sum$return);
break
case 'med'
return array_sum$array) / count$array); //count($array);
break
case 'meded'
return array_fusionarrayarray_fusion$array, 'positive')), 'med');
break
}
}