예제 #1
0
function createVisual($con)
{
    $nodes = checkNodesGlobalVariable($con);
    $products = checkProductsGlobalVariable($con);
    $pairs = '';
    $visual = '';
    $betweenness = getBetweenness();
    foreach ($nodes as $row) {
        $visual .= 'n' . $row['id'] . '{';
        //set node visual properties
        $visual .= 'shape:dot, color:' . genColor($row['links'], $betweenness[0], $betweenness[1]) . ', ';
        // set serves and requests
        if ($row['serves']) {
            $visual .= 'serves: ' . str_replace('^', ', ', $row['serves']) . ',';
        }
        if ($row['requests']) {
            $visual .= ' requests: ' . str_replace('^', ', ', $row['requests']) . ',';
        }
        // set wealth
        $visual .= ' money: ' . $row['money'];
        // add new-lines
        $visual .= "}\n\n";
        // set links
        if (isset($row['links'])) {
            foreach (explode(',', $row['links']) as $value) {
                // hacky solution, but avoids duplicates by searching for a simple |n0-n1| pairs in a string
                if (strpos($pairs, '|n' . $value . '-n' . $row['id'] . '|') === false) {
                    $pairs .= '|n' . $row['id'] . '-n' . $value . '|';
                    $visual .= 'n' . $row['id'] . "--n{$value} {color: #777777, weight: 1.5}\n\n";
                }
            }
        }
    }
    return $visual;
}
예제 #2
0
        $b = $g = $r;
    }
    $_r = mt_rand($br, $r);
    $_g = mt_rand($bg, $g);
    $_b = mt_rand($bb, $b);
    return imagecolorallocatealpha($image, $_r, $_g, $_b, $a);
}
captcha();
$width = 250;
$height = 60;
$font = array('RiseStarHandRegular.otf');
$image = imagecreatetruecolor($width, $height);
$text = $_SESSION['captcha'];
$bg = imagecolorallocate($image, 255, 255, 255);
imagefilledrectangle($image, 1, 1, $width - 2, $height - 2, $bg);
imagealphablending($image, true);
$pa = 8;
for ($a = 1; $a <= $pa; $a++) {
    $p = $a / $pa;
    imageline($image, 1, $height * $p, $width - 2, $height * $p, imagecolorallocate($image, 127, 186, 190));
    imageline($image, $width * $p, 1, $width * $p, $height - 2, imagecolorallocate($image, 127, 186, 190));
}
imagettftext($image, $height * 0.4, 0, mt_rand($width * 0.1, $width * 0.3), mt_rand($height * 0.33, $height * 0.85), genColor(80), $font[array_rand($font)], substr($text, 0, 2));
imagettftext($image, $height * 0.4, 0, mt_rand($width * 0.4, $width * 0.55), mt_rand($height * 0.33, $height * 0.85), genColor(100), $font[array_rand($font)], substr($text, 2, 2));
imagettftext($image, $height * 0.4, 0, mt_rand($width * 0.6, $width * 0.8), mt_rand($height * 0.33, $height * 0.85), genColor(100), $font[array_rand($font)], substr($text, 4, 2));
for ($i = 0; $i < 8; $i++) {
    imagefilledarc($image, mt_rand($width * 0.15, $width * 0.8), mt_rand($height * 0.15, $height * 0.8), $height * 0.4, $height * 0.4, 0, 360, genColor(255, 180, 255, 110, 255, 90, 110), IMG_ARC_PIE);
}
header("Content-type: image/png");
imagepng($image);
imagedestroy($image);