function skew_image ($image, $skew_value
{
// note: this function was original posted by etienne on php.net.
$width = imagesx$image);
$height = imagesy$image);
$height2 = $height + ($width * $skew_value);
$imgdest = image_create_alpha$width, $height2);
// Process the image
for$x = 0, $level = 0; $x < $width - 1; $x++)
{
$floor = floor$level);
// To go faster, some lines are being copied at once
if ($level == $floor
imagecopy$imgdest, $image, $x, $level, $x, 0, 1, $height - 1);
else
{
$temp = $level - $floor
// The first pixel of the line
// We get the color then apply a fade on it depending on the level
$color1 = imagecolorsforindex$image, imagecolorat$img, $x, 0));
$alpha = $color1'alpha'] + ($temp * 127);
if ($alpha < 127)
{
$color = imagecolorallocatealpha$imgdest, $color1'red'], $color1'green'], $color1'blue'], $alpha);
imagesetpixel$imgdest, $x, $floor, $color);
}
// The rest of the line
for$y = 1; $y < $height - 1; $y++)
{
// Merge this pixel and the upper one
$color2 = imagecolorsforindex$image, imagecolorat$image, $x, $y));
$alpha = ($color1'alpha'] * $temp) + ($color2'alpha'] * (1 - $temp));
if ($alpha < 127)
{
$red = ($color1'red'] * $temp) + ($color2'red'] * (1 - $temp));
$green = ($color1'green'] * $temp) + ($color2'green'] * (1 - $temp));
$blue = ($color1'blue'] * $temp) + ($color2'blue'] * (1 - $temp));
$color = imagecolorallocatealpha$imgdest, $red, $green, $blue, $alpha);
imagesetpixel$imgdest, $x, $floor + $y, $color);
}
$color1 = $color2
}
// The last pixel of the line
$color1 = imagecolorsforindex$image, imagecolorat$image, $x, $height - 1));
$alpha = $color1'alpha'] + ((1 - $temp) * 127);
if ($alpha < 127)
{
$color = imagecolorallocatealpha$imgdest, $color1'red'], $color1'green'], $color1'blue'], $alpha);
imagesetpixel$imgdest, $x, $floor + $height - 1, $color);
}
}
// The line is finished, the next line will be lower
$level += $skew_value
}
// Finished processing, return the skewed image
return $imgdest
}
Tag: Passkey
eXorithm – Execute Algorithm: View / Run Algorithm simple_download
function simple_download ()
{
$data = 'iVBORw0KGgoAAAANSUhEUgAAABwAAAASCAMAAAB/2U7WAAAABl'
. 'BMVEUAAAD///+l2Z/dAAAASUlEQVR4XqWQUQoAIAxC2/0vXZDr'
. 'EX4IJTRkb7lobNUStXsB0jIXIAMSsQnWlsV+wULF4Avk9fLq2r'
. '8a5HSE35Q3eO2XP1A1wQkZSgETvDtKdQAAAABJRU5ErkJggg=='
$data = base64_decode$data);
return array'extension'=>'png', 'name'=>'phprules', 'data'=>$data);
}
eXorithm – Execute Algorithm: View / Run Algorithm set_unix_time
function set_unix_time ($year$month$day$hour$minute$second
{
return mktime$hour$minute$second$month$day$year);
}
eXorithm – Execute Algorithm: View / Run Algorithm simplify_equation
function simplify_equation ($equation
{
if (is_array$equation)) {
// first simply the parameters of the equation
$equation[1] = simplify_equation$equation[1]);
if (isset$equation[2])) {
$equation[2] = simplify_equation$equation[2]);
}
// simplify based on the operator
switch ($equation[0]) {
case '+'
if ((is_numeric$equation[1])) && (is_numeric$equation[2]))) {
return $equation[1]+$equation[2];
}
if ($equation[1]===0) {
return $equation[2];
}
if ($equation[2]===0) {
return $equation[1];
}
return $equation
case '-'
if ($equation[1]===$equation[2]) {
return 0;
}
if ((is_numeric$equation[1])) && (is_numeric$equation[2]))) {
return $equation[1]-$equation[2];
}
if ($equation[1]===0) {
return array'neg', $equation[2]);
}
if ($equation[2]===0) {
return $equation[1];
}
return $equation
case '*'
if ((is_numeric$equation[1])) && (is_numeric$equation[2]))) {
return $equation[1]*$equation[2];
}
if ($equation[1]===0) {
return 0;
}
if ($equation[2]===0) {
return 0;
}
if ($equation[1]===1) {
return $equation[2];
}
if ($equation[2]===1) {
return $equation[1];
}
return $equation
case '/'
if ($equation[2]===0) {
throw new Exception'division by zero');
}
if ($equation[1]===$equation[2]) {
return 1;
}
if ((is_numeric$equation[1])) && (is_numeric$equation[2]))) {
if (($equation[1] % $equation[2])==0) {
return $equation[1]/$equation[2];
} else {
// get the greastest common divisor
$gcd = gcd_euclid$equation[1], $equation[2]);
$equation[1] = $equation[1]/$gcd
$equation[2] = $equation[2]/$gcd
}
}
if ($equation[1]===0) {
return 0;
}
if ($equation[2]===1) {
return $equation[1];
}
return $equation
case '^'
if ((is_numeric$equation[1])) && (is_numeric$equation[2]))) {
return pow$equation[1], $equation[2]);
}
if ($equation[1]===0) {
return 0;
}
if ($equation[1]===1) {
return 1;
}
if ($equation[2]===0) {
return 1;
}
if ($equation[2]===1) {
return $equation[1];
}
return $equation
case 'neg'
if (is_array$equation[1])) {
if ($equation[1][0]=='neg') {
return $equation[1][1];
}
}
if (is_numeric$equation[1])) {
return $equation[1]*-1;
}
return $equation
case 'sqrt'
if (is_numeric$equation[1])) {
return sqrt$equation[1]);
}
return $equation
case 'log'
if ($equation[1]===1) {
return 0;
}
if ((is_numeric$equation[1])) && (is_numeric$equation[2]))) {
return log$equation[1], $equation[2]);
}
return $equation
case 'ln'
if (is_numeric$equation[1])) {
return log$equation[1]);
}
return $equation
case 'exp'
if (is_numeric$equation[1])) {
return exp$equation[1]);
}
return $equation
case 'root'
if ((is_numeric$equation[1])) && (is_numeric$equation[2]))) {
return pow$equation[1], 1/$equation[2]);
}
if ($equation[1]===0) {
return 0;
}
if ($equation[1]===1) {
return 1;
}
if ($equation[2]===0) {
throw new Exception'division by zero');
}
if ($equation[2]===1) {
return $equation[1];
}
return $equation
// trig
case 'sin'
if (is_numeric$equation[1])) {
return sin$equation[1]);
}
return $equation
case 'cos'
if (is_numeric$equation[1])) {
return cos$equation[1]);
}
return $equation
case 'tan'
if (is_numeric$equation[1])) {
return tan$equation[1]);
}
return $equation
case 'sec'
if (is_numeric$equation[1])) {
return 1/cos$equation[1]);
}
return $equation
case 'csc'
if (is_numeric$equation[1])) {
return 1/sin$equation[1]);
}
return $equation
case 'cot'
if (is_numeric$equation[1])) {
return 1/tan$equation[1]);
}
return $equation
// hyperbolic trig
case 'sinh'
if (is_numeric$equation[1])) {
return sinh$equation[1]);
}
return $equation
case 'cosh'
if (is_numeric$equation[1])) {
return cosh$equation[1]);
}
return $equation
case 'tanh'
if (is_numeric$equation[1])) {
return tanh$equation[1]);
}
return $equation
case 'sech'
if (is_numeric$equation[1])) {
return 1/cosh$equation[1]);
}
return $equation
case 'csch'
if (is_numeric$equation[1])) {
return 1/sinh$equation[1]);
}
return $equation
case 'coth'
if (is_numeric$equation[1])) {
return 1/tanh$equation[1]);
}
return $equation
// arc trig
case 'arcsin'
if (is_numeric$equation[1])) {
return asin$equation[1]);
}
return $equation
case 'arccos'
if (is_numeric$equation[1])) {
return acos$equation[1]);
}
return $equation
case 'arctan'
if (is_numeric$equation[1])) {
return atan$equation[1]);
}
return $equation
// inverse hyperbolic trig
case 'arsinh'
if (is_numeric$equation[1])) {
return asinh$equation[1]);
}
return $equation
case 'arcosh'
if (is_numeric$equation[1])) {
return acosh$equation[1]);
}
return $equation
case 'artanh'
if (is_numeric$equation[1])) {
return atanh$equation[1]);
}
return $equation
default
throw new Exception'usupported operator '$operator);
}
}
return $equation
}
eXorithm – Execute Algorithm: View / Run Algorithm round_corners
function round_corners ($image, $radius, $color, $transparency
{
$width = imagesx$image);
$height = imagesy$image);
$image2 = imagecreatetruecolor$width, $height);
imagesavealpha$image2, true);
imagealphablending$image2, false);
imagecopy$image2, $image, 0, 0, 0, 0, $width, $height);
$full_color = allocate_color$image2, $color, $transparency);
// loop 4 times, for each corner...
for ($left=0;$left<=1;$left++) {
for ($top=0;$top<=1;$top++) {
$start_x = $left * ($width$radius);
$start_y = $top * ($height$radius);
$end_x = $start_x$radius
$end_y = $start_y$radius
$radius_origin_x = $left * ($start_x-1) + (!$left) * $end_x
$radius_origin_y = $top * ($start_y-1) + (!$top) * $end_y
for ($x$start_x$x$end_x$x++) {
for ($y$start_y$y$end_y$y++) {
$dist = sqrtpow$x$radius_origin_x,2)+pow$y$radius_origin_y,2));
if ($dist>($radius+1)) {
imagesetpixel$image2, $x, $y, $full_color);
} else {
if ($dist$radius) {
$pct = 1-($dist$radius);
$color2 = antialias_pixel$image2, $x, $y, $full_color, $pct);
imagesetpixel$image2, $x, $y, $color2);
}
}
}
}
}
}
return $image2
}
eXorithm – Execute Algorithm: View / Run Algorithm rounded_rectangle
function rounded_rectangle ($height, $width, $corner_radius, $rectangle_color, $background_color, $background_transparent
{
if (($corner_radius>($height/2)) || ($corner_radius>($width/2))) {
throw new Exception'Corner radius may not exceed half the length of any of the sides.');
}
$image = image_create_alpha$width, $height);
if (!$background_transparent) {
$background_color = allocate_color$image, $background_color);
imagefilledrectangle$image, 0, 0, $width, $height, $background_color);
}
$rectangle_color = allocate_color$image, $rectangle_color);
// draw 2 rectangles that overlap (making an image like the cross on the Swiss flag)
imagefilledrectangle$image, $corner_radius, 0, $width$corner_radius-1, $height, $rectangle_color);
imagefilledrectangle$image, 0, $corner_radius, $width, $height$corner_radius-1, $rectangle_color);
// draw 4 circles for the corners
imagefilledellipse$image, $corner_radius, $corner_radius, $corner_radius*2, $corner_radius*2, $rectangle_color);
imagefilledellipse$image, $width$corner_radius-1, $corner_radius, $corner_radius*2, $corner_radius*2, $rectangle_color);
imagefilledellipse$image, $corner_radius, $height$corner_radius-1, $corner_radius*2, $corner_radius*2, $rectangle_color);
imagefilledellipse$image, $width$corner_radius-1, $height$corner_radius-1, $corner_radius*2, $corner_radius*2, $rectangle_color);
return $image
}
eXorithm – Execute Algorithm: View / Run Algorithm snowflake_fractal
function snowflake_fractal ($length, $level, $color, $image, $x, $y, $orientation
{
if ($image==='') {
// initialize
$image = image_create_alpha$length+2, round$length*4/3*sindeg2rad(60)))+2);
$x = $length+1;
$y = round$length/3*sindeg2rad(60)))+1;
$orientation = -90;
$r = hexdecsubstr$color, 0, 2));
$g = hexdecsubstr$color, 2, 2));
$b = hexdecsubstr$color, 4, 2));
$color = imagecolorallocate$image, $r, $g, $b);
$start = true;
} else {
$start = false;
}
if ($level==0) {
// all drawing is done at depth 0
$x2 = ($length)*sindeg2rad$orientation))+$x
$y2 = ($length)*cosdeg2rad$orientation))+$y
imageline$image, round$x), round$y), round$x2), round$y2), $color);
// keep track of the image, current location, and the direction we're facing
return array$image, $x2, $y2, $orientation);
} else {
// draw a side (Koch curve)
list$image, $x, $y, $orientation) = snowflake_fractal$length/3, $level-1, $color, $image, $x, $y, $orientation);
$orientation = ($orientation-60) % 360;
list$image, $x, $y, $orientation) = snowflake_fractal$length/3, $level-1, $color, $image, $x, $y, $orientation);
$orientation = ($orientation+120) % 360;
list$image, $x, $y, $orientation) = snowflake_fractal$length/3, $level-1, $color, $image, $x, $y, $orientation);
$orientation = ($orientation-60) % 360;
list$image, $x, $y, $orientation) = snowflake_fractal$length/3, $level-1, $color, $image, $x, $y, $orientation);
// draw the other two sides
if ($start) {
$orientation = ($orientation+120) % 360;
list$image, $x, $y, $orientation) = snowflake_fractal$length, $level, $color, $image, $x, $y, $orientation);
$orientation = ($orientation+120) % 360;
list$image, $x, $y, $orientation) = snowflake_fractal$length, $level, $color, $image, $x, $y, $orientation);
return $image
} else {
// keep track of the image, current location, and the direction we're facing
return array$image, $x, $y, $orientation);
}
}
}
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 scientific_notation
function scientific_notation ($value, $condensed
{
$e = 0;
while$value>=10 || $value<1)
{
if$value<=1)
{
$value *= 10;
$e--;
}
else
{
if$value>=10)
{
$value /= 10;
$e++;
}
}
}
if$condensed
return $value . "E" . $e
return $value . " x 10<sup>" . $e . "</sup>"
}