|
Познавший АНТИЧАТ
Регистрация: 02.06.2006
Сообщений: 1,188
Провел на форуме: 6023777
Репутация:
2642
|
|
Для брата писал, мож кому и здесь пригодится
PHP код:
<?php
if(isset($_GET['a']) && isset($_GET['b']) && isset($_GET['c']) && $_GET['width'] >= 50 && $_GET['width'] <= 1280 && $_GET['height'] >= 50 && $_GET['height'] <= 1280) {
header('Content-Type: image/png');
$a = $_GET['a'];
$b = $_GET['b'];
$c = $_GET['c'];
$y = create_function('$x', 'return ('.$a.' * $x * $x) + ('.$b.' * $x) + '.$c.';');
$top = array();
$top['x'] = (-1 * $b) / (2 * $a);
$top['y'] = $y($top['x']);
$img_width = $_GET['width'];
$img_height = $_GET['height'];
$delimetr = round((($img_width+$img_height)/2)/20); //px
$image = imagecreatetruecolor($img_width, $img_height);
imagefill($image, 0, 0, 0xFFFFFF);
$x = array($top['x']-3, $top['x']-2, $top['x']-1, $top['x'], $top['x']+1, $top['x']+2, $top['x']+3);
for($sqrx = ($x[0] * $delimetr)-1; $sqrx <= ($x[count($x)-1] * $delimetr); $sqrx++) {
$coordx = (($img_width/2)+$sqrx);
$coordy = (($img_height/2)-$y($sqrx/$delimetr)*$delimetr);
$coordxx = (($img_width/2)+($sqrx+1));
$coordyy = (($img_height/2)-$y(($sqrx+1)/$delimetr)*$delimetr);
if(in_array(($sqrx/$delimetr), $x)) {
imageline($image, $coordx, $coordy, $coordx, ($img_height/2), 0x00FF00);
imageline($image, $coordx, $coordy, ($img_width/2), $coordy, 0x00FF00);
imageline($image, $coordx-1, $coordy-1, $coordx-1, $coordy+1, 0x5F5F5F);
imageline($image, $coordx, $coordy-1, $coordx, $coordy+1, 0x5F5F5F);
imageline($image, $coordx+1, $coordy-1, $coordx+1, $coordy+1, 0x5F5F5F);
}
imageline($image, $coordx, $coordy, $coordxx, $coordyy, 0xFF0000);
}
for($w = (($img_width/2) - $delimetr); $w >= 0; $w -= $delimetr) {
imageline($image, $w, (($img_height/2)+2), $w, (($img_height/2)-2), 0x5F5F5F);
}
for($w = (($img_width/2) + $delimetr); $w <= $img_width; $w += $delimetr) {
imageline($image, $w, (($img_height/2)+2), $w, (($img_height/2)-2), 0x5F5F5F);
}
for($h = (($img_height/2) + $delimetr); $h <= $img_height; $h += $delimetr) {
imageline($image, (($img_width/2)+2), $h, (($img_width/2)-2), $h, 0x5F5F5F);
}
for($h = (($img_height/2) - $delimetr); $h >= 0; $h -= $delimetr) {
imageline($image, (($img_width/2)+2), $h, (($img_width/2)-2), $h, 0x5F5F5F);
}
imageline($image, ($img_width/2), 0, ($img_width/2), $img_height, 0x5F5F5F);
imageline($image, 0, ($img_height/2), $img_width, ($img_height/2), 0x5F5F5F);
imagepng($image);
imagedestroy($image);
} else {
echo('<form method="GET">
Функция: y = <input type="text" name="a" value="1" size="3">x<sup>2</sup> + <input type="text" name="b" value="0" size="3">x + <input type="text" name="c" value="0" size="3"><br>
Ширина картинки <input type="text" name="width" value="800" size="3"><br>
Высота картинки <input type="text" name="height" value="800" size="3"><br>
<input type="submit" value="Go!">
</form>');
}
?>
|