function draw_triangle ($points, $color
{
if (count$points)!=6) {
throw new Exception'The points must be an array of 6 integers.');
}
$image = image_create_alphamax$points[0], $points[2], $points[4])+1, max$points[1], $points[3], $points[5])+1);
$red = hexdecsubstr$color, 0, 2));
$green = hexdecsubstr$color, 2, 2));
$blue = hexdecsubstr$color, 4, 2));
$color = imagecolorallocatealpha$image, $red, $green, $blue, 0);
imagefilledpolygon$image, $points, 3, $color);
return $image
}
Category: Algorithm
eXorithm – Execute Algorithm: View / Run Algorithm simple_recursor
function simple_recursor ($count
{
if ($count>=10) {
return $count
} else {
$x = simple_recursor$count+1);
return $x" - "$count
}
}
eXorithm – Execute Algorithm: View / Run Algorithm draw_pyramid
function draw_pyramid ($image_size, $degree_x, $degree_y, $degree_z, $vdist, $dist, $vertex_color, $side_color, $wireframe, $dashes
{
$degree_x = $degree_x % 360;
$degree_y = $degree_y % 360;
$degree_z = $degree_z % 360;
// construct the cube polygons
$size = 400; // the size is arbitrary
$x1$size/2;
$x0$x1*-1;
$y1$size/2;
$y0$y1*-1;
$z1$size/2;
$z0$z1*-1;
$sides = array();
$sides[] = array$x0$y0$z0, 0,0,$z1, $x0$y1$z0);
$sides[] = array$x1$y0$z0, 0,0,$z1, $x1$y1$z0);
$sides[] = array$x0$y0$z0, 0,0,$z1, $x1$y0$z0);
$sides[] = array$x0$y1$z0, 0,0,$z1, $x1$y1$z0);
$sides[] = array$x0$y0$z0, $x0$y1$z0, $x1$y1$z0, $x1$y0$z0);
// project each of the 6 polygons that makes up the cube
for ($i=0; $icount$sides); $i++) {
$points[] = project_polygon$sides$i], $degree_x, $degree_y, $degree_z, 0, 0, 0, $vdist+($size/2), $dist+($size/2), true);
}
// scale the image somewhat
$scale = $image_size/($size*1.3);
return render_polygons$points, $vertex_color, $side_color, $wireframe, $dashes, $image_size, $scale);
}
eXorithm – Execute Algorithm: View / Run Algorithm add_transparency
function add_transparency ($image, $percent
{
$x = imagesx$image);
$y = imagesy$image);
$image2 = image_create_alpha$x, $y);
imagecopy$image2, $image, 0, 0, 0, 0, $x, $y);
imagesavealpha$image2, true);
if ($percent>0) {
for ($ii=0;$ii$x$ii++) {
for ($jj=0;$jj$y$jj++) {
$c = imagecolorat$image2, $ii, $jj);
$r = ($c >> 16) & 0xFF;
$g = ($c >> 8) & 0xFF;
$b = $c & 0xFF;
$alpha = ($c >> 24) & 0xFF;
$c = imagecolorallocatealpha$image2, $r, $g, $b, $alpha+($percent/100*(127-$alpha)));
imagesetpixel$image2, $ii, $jj, $c);
}
}
}
return $image2
}
eXorithm – Execute Algorithm: History For Algorithm pi_digits
Duotone Image
<?php /** * duotone_image * * Change an image into a tinted grayscale. * * @version 0.5 * @author Contributors at eXorithm * @link /algorithm/view/duotone_image Listing at eXorithm * @link /algorithm/history/duotone_image History at eXorithm * @license /home/show/license * * @param resource $image (GD image) The image to duotone. * @param number $rplus Red value to increase or decrease. * @param number $gplus Green value to increase or decrease. * @param number $bplus Blue value to increase or decrease. * @param bool $pcnt If checked, the values for rplus, gplus and bplus will be treated as percentages. * @return resource GD image */ function duotone_image($image=null,$rplus=0,$gplus=0,$bplus=60,$pcnt=false) { // Adapted from http://www.tuxradar.com/practicalphp/11/2/21 $imagex = imagesx($image); $imagey = imagesy($image); $image2 = imagecreatetruecolor($imagex, $imagey); imagesavealpha($image2, true); imagealphablending($image2, false); for ($x = 0; $x <$imagex; ++$x) { for ($y = 0; $y <$imagey; ++$y) { $rgb = imagecolorat($image, $x, $y); $color = imagecolorsforindex($image, $rgb); $grey = floor(($color['red']+$color['green']+$color['blue'])/3); if ($pcnt) { $red = $grey + $grey*($rplus/150); $green = $grey + $grey*($gplus/150); $blue = $grey + $grey*($bplus/150); } else { $red = $grey + $rplus; $green = $grey + $gplus; $blue = $grey + $bplus; } if ($red > 255) $red = 255; if ($green > 255) $green = 255; if ($blue > 255) $blue = 255; if ($red < 0) $red = 0; if ($green < 0) $green = 0; if ($blue < 0) $blue = 0; $newcol = imagecolorallocatealpha($image2, $red,$green,$blue,$color['alpha']); imagesetpixel ($image2, $x, $y, $newcol); } } return $image2; } ?>
eXorithm – Execute Algorithm: Embed Algorithm address_elevation
Embed This Algorithm
This page will help you embed the algorithm address_elevation 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 google_translate
function google_translate ($text, $from, $to
{
$transfile_get_contents"http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q="urlencode$text)."&langpair="urlencode$from)."|"urlencode$to));
$json = json_decode$trans);
if (!isset$json->responseStatus) || ($json->responseStatus!=200)) {
throw new Exception"Translation could not be retreived for '$text'");
}
return $json->responseData->translatedText;
}
eXorithm – Execute Algorithm: View / Run Algorithm image_callback
function image_callback ($image, $operation
{
/* perform a series of transformation on an image */
switch ($operation) {
case "flip"
$image = flip_image$image, "vertical");
break
case "skew"
$image = skew_image$image, 0.5);
break
case "invert"
$image = invert_image$image);
break
}
$ret = array();
$ret"return"] = $image
$ret"handler"] = HANDLER_IMAGE;
$ret"arguments"] = array$image);
return $ret
}
eXorithm – Execute Algorithm: View / Run Algorithm hello_world
function hello_world ()
{
return "Hello World"
}