draw_triangle    version 0.4    Draw a filled triangle.
Category: Algorithm
eXorithm – Execute Algorithm: Embed Algorithm round_corners
Embed This Algorithm
This page will help you embed the algorithm round_corners 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 scale_image
function scale_image ($image, $width, $height, $percent
{
$ewidth = imagesx$image);
$eheight = imagesy$image);
if ($percent) {
$width = round(($width/100)*$ewidth);
$height = round(($height/100)*$eheight);
}
$image2 = image_create_alpha$width, $height);
for ($x=0;$x$width$x++) {
$x1 = floor$x * ($ewidth$width));
for ($y=0;$y$height$y++) {
$y1 = floor$y * ($eheight$height));
$index = imagecolorat$image, $x1, $y1);
$color = imagecolorsforindex$image, $index);
$trans = imagecolorallocatealpha$image2
$color'red'],
$color'green'],
$color'blue'],
$color'alpha']);
imagesetpixel$image2, $x, $y, $trans);
}
}
return $image2
}
eXorithm – Execute Algorithm: View / Run Algorithm pi_digits
function pi_digits ($digits
{
$n = floor$digits * 14/4);
$scale = 10000;
$init = 2000;
$carry = 0;
$result = ''
for$i=0;$i<=$n$i++) {
$arr$i] = $init
}
for$i$n$i>0;$i$i-14) {
$sum = 0;
for$j$i$j>0;$j--) {
$sum = ($sum * $j) + ($scale * $arr$j]);
$arr$j] = $sum % (($j*2)-1);
$sum = floor$sum / (($j*2)-1));
}
$result .= sprintf"%04d", ($carry + ($sum / $scale)));
$carry = $sum % $scale;
}
if ($digits>1) {
return $result[0].'.'substr$result,1,$digits-1);
} else {
return substr$result,0,$digits);
}
}
eXorithm – Execute Algorithm: View / Run Algorithm collection_from_freebase
function collection_from_freebase ($topic, $collection
{
// construct the query
$simplequery = array'id'=>$topic, $collection=>array());
// issue the query
$results = freebase_query$simplequery);
// get the result
if (isset$results[0][$collection])) {
$array = $results[0][$collection];
} else {
$array = array(); // not there? return empty array
}
// sort and return
sort$array);
return $array
}
eXorithm – Execute Algorithm: Embed Algorithm unity
Embed This Algorithm
This page will help you embed the algorithm unity 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 even_number
function even_number ($number
{
return (($number%2)==0);
}
eXorithm – Execute Algorithm: View / Run Algorithm weather_forecast
function weather_forecast ($location, $units, $header_color, $day_header_color, $day_color
{
$weather = file_get_contents'http://www.google.com/ig/api?weather='urlencode$location));
$xml = simplexml_load_string$weather);
if (!isset$xml->weather->forecast_conditions)) {
throw new Exception'Data could not be retreived for location '$location);
}
$location = $xml->weather->forecast_information->city['data'];
// four day outlook
for ($i = 0; $i < 4; $i++){
if ($xml->weather->forecast_conditions->$i) {
$forecast_day[] = $xml->weather->forecast_conditions->$i->day_of_week['data'];
$forecast_condition[] = $xml->weather->forecast_conditions->$i->condition['data'];
$low = $xml->weather->forecast_conditions->$i->low['data'];
if ($units=='k'
$low = round((($low - 32)*5/9) + 273, 1);
else if ($units=='c'
$low = round(($low - 32)*5/9, 1);
$forecast_low[] = $low
$high = $xml->weather->forecast_conditions->$i->high['data'];
if ($units=='k'
$high = round((($high - 32)*5/9) + 273, 1);
else if ($units=='c'
$high = round(($high - 32)*5/9, 1);
$forecast_high[] = $high
$forecast_icon[] = $xml->weather->forecast_conditions->$i->icon['data'];
}
}
// current
$condition = $xml->weather->current_conditions->condition['data'];
$temp = $xml->weather->current_conditions->temp_f['data'];
if ($units=='k'
$temp = round((($temp - 32)*5/9) + 273, 1);
else if ($units=='c'
$temp = round(($temp - 32)*5/9, 1);
$icon = $xml->weather->current_conditions->icon['data'];
// build the HTML
$header = "<tr><td colspan=""count$forecast_day)."" bgcolor="#$header_color">"
if ($icon!=''
$header .= "<img align="left" src="http://www.google.com$icon">"
$header .= "<b>$location</b><br>Currently <i>$condition</i> <b>$temp$units</b>"
$header .= "</td></tr>n<tr>"
$data = "<tr>n"
for ($i = 0; $i < count$forecast_day); $i++){
$header .= "<td width="130" bgcolor="#$day_header_color"><b>$forecast_day[$i]</b></td>"
$data .= "<td bgcolor="#$day_color">"
$data .= "<img src="http://www.google.com$forecast_icon[$i]">"
$data .= "<br><i>$forecast_condition[$i]</i>"
$data .= "<br>high <b>$forecast_high[$i]$units</b>"
$data .= "<br>low <b>$forecast_low[$i]$units</b>"
$data .= "</td>n"
}
$header .= "</tr>"
$data .= "</tr>"
return "<table cellpadding="5" cellspacing="3">n$headern$datan</table>"
}
eXorithm – Execute Algorithm: Algorithms Beginning with Z
Create Gradient
<?php /** * create_gradient * * Create an image that is a color gradient. * * @version 0.1 * @author Contributors at eXorithm * @link /algorithm/view/create_gradient Listing at eXorithm * @link /algorithm/history/create_gradient History at eXorithm * @license /home/show/license * * @param string $start_color (hex color code) The start color of the gradient. * @param string $end_color (hex color code) The end color of the gradient. * @param number $size The length of the resulting image. * @param number $thickness The thickness of the resulting image. * @param mixed $orientation The orientation of the gradient. * @return resource GD image */ function create_gradient($start_color='ffffff',$end_color='000000',$size=100,$thickness=5,$orientation='') { if ($orientation=="vertical") { $img=imagecreatetruecolor($thickness,$size); } else { $img=imagecreatetruecolor($size,$thickness); } $start_r = hexdec(substr($start_color, 0, 2)); $start_g = hexdec(substr($start_color, 2, 2)); $start_b = hexdec(substr($start_color, 4, 2)); $end_r = hexdec(substr($end_color, 0, 2)); $end_g = hexdec(substr($end_color, 2, 2)); $end_b = hexdec(substr($end_color, 4, 2)); for ($i=0;$i<$size;$i++) { $red = round($start_r - ($start_r-$end_r) * ($i / ($size-1))); $green = round($start_g - ($start_g-$end_g) * ($i / ($size-1))); $blue = round($start_b - ($start_b-$end_b) * ($i / ($size-1))); $color = imagecolorallocate($img, $red, $green, $blue); if ($orientation=="vertical") { for ($k=0;$k<$thickness;$k++) imagesetpixel($img, $k, $i, $color); } else { for ($k=0;$k<$thickness;$k++) imagesetpixel($img, $i, $k, $color); } } return $img; } ?>