<?php
//직선 그리기
function imageline_bresenham(& $im, $startX, $startY, $endX, $endY, $color){
//기준점 계산, 작은 쪽이 출발점, 큰쪽이 도착점
if($endX < $startX){
$dx = $startX - $endX;
$tmpX = $endX;
$tmpgoX = $startX;
}
else{
$dx = $endX - $startX;
$tmpX = $startX;
$tmpgoX = $endX;
}
if($endY < $startY){
$dy = $startY - $endY;
$tmpY = $endY;
$tmpgoY = $startY;
}
else{
$dy = $endY - $startY;
$tmpY = $startY;
$tmpgoY = $endY;
}
/* 기울기에 따른 계산*/
if($dx >= $dy) { //기울기가 1보다 작거나 같을때
$d = $dy * 2 - $dx; //d의 값을 초기화
$incrE = $dy * 2; // E로의 이동을 위해서 쓰이는 증가
$incrNE = ($dy - $dx) * 2; // NE로의 이동을 위해서 쓰이는 증가
$start = $tmpX;
$end = $tmpgoX;
}
else { //기울기가 1보다 클때
$d = $dx * 2 - $dy;
$incrE = $dx * 2;
$incrNE = ($dx - $dy) * 2;
$start = $tmpY;
$end = $tmpgoY;
}
//x, y 좌표 초기화
$x = $startX;
$y = $startY;
imagesetpixel($im, $x, $y, $color);//시작점 찍음
while($start < $end) {
if( $d <= 0) { /*D값이 0보다 작으면 E를 선택 하나의 축만 이동*/
$d += $incrE;
if($dx >= $dy) { // 기울기가 1보다 작을때 X좌표만 증가
if($endX < $startX)
$x--;
else
$x++;
}
else { // 기울기가 1보다 클때 Y좌표만 증가
if($endY < $startY)
$y--;
else
$y++;
}
}
else { /*D값이 0보다 클때 NE를 선택 X,Y 를 같이 이동시킨다.*/
$d += $incrNE;
if($endX < $startX)
$x--;
else
$x++;
if($endY < $startY)
$y--;
else
$y++;
}
imagesetpixel($im, $x, $y, $color);
$start ++;
}
}
function imagearc_bresenham(& $im, $centerX, $centerY, $width, $height, $color) {
$w_r = ceil($width / 2);
$h_r = ceil($height / 2);
$x = 0;
$y = $h_r;
$w_r_square = $w_r * $w_r;
$h_r_square = $h_r * $h_r;
$d = (4 * $h_r_square + $w_r_square * (1 - (4 * $h_r))) / 4;
imagesetpixel($im, $x + $centerX, $y + $centerY, $color);
imagesetpixel($im, $centerX - $x, $y + $centerY, $color);
imagesetpixel($im, $x + $centerX, $centerY - $y , $color);
imagesetpixel($im, $centerX - $x, $centerY - $y, $color);
// $x 독립변수 구간
while($h_r_square * $x < $w_r_square * $y){
++$x;
if($d < 0){
$d += $h_r_square * (2 * $x + 1);
}
else {
--$y;
$d += $h_r_square * (2 * $x + 1) - (2 * $w_r_square * $y);
}
imagesetpixel($im, $x + $centerX, $y + $centerY, $color);
imagesetpixel($im, $centerX - $x, $y + $centerY, $color);
imagesetpixel($im, $x + $centerX, $centerY - $y, $color);
imagesetpixel($im, $centerX - $x, $centerY - $y, $color);
}
// $y 독립변수 구간
$x = $w_r;
$y = 0;
$d = (4 * $w_r_square + $h_r_square * (1 - (4 * $w_r))) / 4;
imagesetpixel($im, $x + $centerX, $y + $centerY, $color);
imagesetpixel($im, $centerX - $x, $y + $centerY, $color);
imagesetpixel($im, $x + $centerX, $centerY - $y, $color);
imagesetpixel($im, $centerX - $x, $centerY - $y, $color);
while($h_r_square * $x > $w_r_square * $y){
++$y;
if($d < 0){
$d += $w_r_square * (2 * $y + 1);
}
else {
--$x;
$d += $w_r_square * (2 * $y + 1) - (2 * $h_r_square * $x);
}
imagesetpixel($im, $x + $centerX, $y + $centerY, $color);
imagesetpixel($im, $centerX - $x, $y + $centerY, $color);
imagesetpixel($im, $x + $centerX, $centerY - $y, $color);
imagesetpixel($im, $centerX - $x, $centerY - $y, $color);
}
}
$w = 400;
$h = 800;
$im = imagecreatetruecolor($w, $h);
$red = imagecolorallocate($im, 255, 0, 0);
imageline_bresenham($im, 200, 200, 100, 0, $red);
imageline_bresenham($im, 200, 200, 400, 100, $red);
imageline_bresenham($im, 200, 200, 400, 200, $red);
imageline_bresenham($im, 200, 200, 400, 300, $red);
imagearc_bresenham($im, 200, 200, 180, 360, $red);
imagearc_bresenham($im, 100, 200, 200, 200, $red);
imageline($im, 200, 600, 100, 400, $red);
imageline($im, 200, 600, 400, 500, $red);
imageline($im, 200, 600, 400, 600, $red);
imageline($im, 200, 600, 400, 700, $red);
imagearc($im, 200, 600, 180, 360, 0, 360, $red);
imagearc($im, 100, 600, 200, 200, 0, 360, $red);
header('Content-Type: image/png');
imagepng($im);
?>
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 5430 | 13년 전 | 1447 | ||
| 5429 |
phpman
|
13년 전 | 861 | |
| 5428 | 13년 전 | 1257 | ||
| 5427 |
phpman
|
13년 전 | 852 | |
| 5426 |
PHPㅡASP프로그래머
|
13년 전 | 1089 | |
| 5425 | 13년 전 | 797 | ||
| 5424 | 13년 전 | 740 | ||
| 5423 | 13년 전 | 735 | ||
| 5422 | 13년 전 | 1836 | ||
| 5421 |
PHPㅡASP프로그래머
|
13년 전 | 810 | |
| 5420 |
|
13년 전 | 1636 | |
| 5419 | 13년 전 | 823 | ||
| 5418 | 13년 전 | 710 | ||
| 5417 | 13년 전 | 626 | ||
| 5416 | 13년 전 | 992 | ||
| 5415 | 13년 전 | 790 | ||
| 5414 | 13년 전 | 728 | ||
| 5413 | 13년 전 | 794 | ||
| 5412 | 13년 전 | 1361 | ||
| 5411 | 13년 전 | 869 | ||
| 5410 | 13년 전 | 1273 | ||
| 5409 | 13년 전 | 4252 | ||
| 5408 | 13년 전 | 989 | ||
| 5407 |
ckflower
|
13년 전 | 2430 | |
| 5406 |
ddokkani
|
13년 전 | 1382 | |
| 5405 | 13년 전 | 1595 | ||
| 5404 | 13년 전 | 664 | ||
| 5403 | 13년 전 | 700 | ||
| 5402 |
밤거리빵빵
|
13년 전 | 6023 | |
| 5401 |
PHPㅡASP프로그래머
|
13년 전 | 979 | |
| 5400 |
|
13년 전 | 1202 | |
| 5399 | 13년 전 | 4996 | ||
| 5398 |
부산아무개
|
13년 전 | 1651 | |
| 5397 | 13년 전 | 2454 | ||
| 5396 | 13년 전 | 1847 | ||
| 5395 | 13년 전 | 1057 | ||
| 5394 | 13년 전 | 1139 | ||
| 5393 | 13년 전 | 1045 | ||
| 5392 |
아르toria
|
13년 전 | 762 | |
| 5391 |
|
13년 전 | 1145 | |
| 5390 |
디지털홍익인간
|
13년 전 | 7705 | |
| 5389 | 13년 전 | 3112 | ||
| 5388 | 13년 전 | 874 | ||
| 5387 |
WaaNee
|
13년 전 | 1915 | |
| 5386 | 13년 전 | 2106 | ||
| 5385 | 13년 전 | 4624 | ||
| 5384 | 13년 전 | 939 | ||
| 5383 | 13년 전 | 2136 | ||
| 5382 | 13년 전 | 666 | ||
| 5381 |
JacobJeon
|
13년 전 | 1086 | |
| 5380 | 13년 전 | 1140 | ||
| 5379 | 13년 전 | 686 | ||
| 5378 | 13년 전 | 10471 | ||
| 5377 | 13년 전 | 866 | ||
| 5376 | 13년 전 | 1461 | ||
| 5375 | 13년 전 | 841 | ||
| 5374 | 13년 전 | 848 | ||
| 5373 | 13년 전 | 2067 | ||
| 5372 | 13년 전 | 1696 | ||
| 5371 |
|
13년 전 | 1642 | |
| 5370 | 13년 전 | 2908 | ||
| 5369 |
아자12345
|
13년 전 | 1020 | |
| 5368 | 13년 전 | 708 | ||
| 5367 | 13년 전 | 1087 | ||
| 5366 | 13년 전 | 2153 | ||
| 5365 | 13년 전 | 1570 | ||
| 5364 | 13년 전 | 1095 | ||
| 5363 |
|
13년 전 | 1362 | |
| 5362 | 13년 전 | 823 | ||
| 5361 | 13년 전 | 1367 | ||
| 5360 | 13년 전 | 721 | ||
| 5359 | 13년 전 | 1376 | ||
| 5358 | 13년 전 | 1210 | ||
| 5357 | 13년 전 | 1610 | ||
| 5356 | 13년 전 | 1105 | ||
| 5355 |
techer
|
13년 전 | 1355 | |
| 5354 |
|
13년 전 | 1019 | |
| 5353 | 13년 전 | 744 | ||
| 5352 | 13년 전 | 826 | ||
| 5351 | 13년 전 | 1206 | ||
| 5350 | 13년 전 | 744 | ||
| 5349 |
|
13년 전 | 1445 | |
| 5348 | 13년 전 | 854 | ||
| 5347 | 13년 전 | 759 | ||
| 5346 | 13년 전 | 876 | ||
| 5345 | 13년 전 | 818 | ||
| 5344 |
후라보노보노
|
13년 전 | 1960 | |
| 5343 | 13년 전 | 1161 | ||
| 5342 | 13년 전 | 1126 | ||
| 5341 | 13년 전 | 2076 | ||
| 5340 |
|
13년 전 | 1120 | |
| 5339 |
AMDbest
|
13년 전 | 743 | |
| 5338 | 13년 전 | 737 | ||
| 5337 |
프로프리랜서
|
13년 전 | 1482 | |
| 5336 |
프로프리랜서
|
13년 전 | 926 | |
| 5335 | 13년 전 | 723 | ||
| 5334 |
|
13년 전 | 974 | |
| 5333 | 13년 전 | 2842 | ||
| 5332 | 13년 전 | 1525 | ||
| 5331 | 13년 전 | 1328 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기