여기 참고 해서 php용으로 만들었습니다.
그런데 결과물은 php내장함수와 거의 똑같네요.
좀 다를 줄 알았는데......
php 내장함수를 사용하지 않고 원이나 타원 직선을 그릴수 있는 정도에 만족해야 할듯합니다.
알고리즘에 대한 설명은 없습니다.
test.php
-----------------------------------------------------------------------------------------------------------------------------
<?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);
?>
샘플 : http://apmusers.com/php_arc.php
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 2630 |
|
15년 전 | 814 | |
| 2629 | 15년 전 | 888 | ||
| 2628 | 15년 전 | 1083 | ||
| 2627 | 15년 전 | 1772 | ||
| 2626 |
angpang
|
15년 전 | 1090 | |
| 2625 |
|
15년 전 | 1179 | |
| 2624 | 15년 전 | 957 | ||
| 2623 | 15년 전 | 895 | ||
| 2622 | 15년 전 | 1269 | ||
| 2621 | 15년 전 | 1736 | ||
| 2620 | 15년 전 | 1010 | ||
| 2619 | 15년 전 | 1347 | ||
| 2618 |
terrorboys
|
15년 전 | 1619 | |
| 2617 |
mummy
|
15년 전 | 970 | |
| 2616 | 15년 전 | 901 | ||
| 2615 |
windday
|
15년 전 | 1052 | |
| 2614 | 15년 전 | 1102 | ||
| 2613 | 15년 전 | 925 | ||
| 2612 | 15년 전 | 1195 | ||
| 2611 | 15년 전 | 1281 | ||
| 2610 | 15년 전 | 1214 | ||
| 2609 | 15년 전 | 3129 | ||
| 2608 |
DiZiNOr
|
15년 전 | 809 | |
| 2607 | 15년 전 | 1358 | ||
| 2606 |
|
15년 전 | 941 | |
| 2605 | 15년 전 | 1759 | ||
| 2604 | 15년 전 | 718 | ||
| 2603 | 15년 전 | 878 | ||
| 2602 |
bitmaster
|
15년 전 | 891 | |
| 2601 | 15년 전 | 895 | ||
| 2600 | 15년 전 | 1626 | ||
| 2599 | 15년 전 | 2932 | ||
| 2598 | 15년 전 | 2013 | ||
| 2597 | 15년 전 | 1930 | ||
| 2596 | 15년 전 | 913 | ||
| 2595 | 15년 전 | 1021 | ||
| 2594 | 15년 전 | 963 | ||
| 2593 |
순천홈페이지
|
15년 전 | 850 | |
| 2592 | 15년 전 | 1138 | ||
| 2591 | 15년 전 | 839 | ||
| 2590 | 15년 전 | 1307 | ||
| 2589 |
dannykim
|
15년 전 | 734 | |
| 2588 |
dannykim
|
15년 전 | 645 | |
| 2587 | 15년 전 | 1531 | ||
| 2586 | 15년 전 | 790 | ||
| 2585 | 15년 전 | 1233 | ||
| 2584 | 15년 전 | 1095 | ||
| 2583 | 15년 전 | 776 | ||
| 2582 | 15년 전 | 800 | ||
| 2581 | 15년 전 | 708 | ||
| 2580 |
|
15년 전 | 688 | |
| 2579 | 15년 전 | 855 | ||
| 2578 | 15년 전 | 1103 | ||
| 2577 | 15년 전 | 2270 | ||
| 2576 |
확실한방법
|
15년 전 | 874 | |
| 2575 | 15년 전 | 955 | ||
| 2574 | 15년 전 | 987 | ||
| 2573 | 15년 전 | 982 | ||
| 2572 | 15년 전 | 1052 | ||
| 2571 |
|
15년 전 | 676 | |
| 2570 | 15년 전 | 1931 | ||
| 2569 |
|
15년 전 | 769 | |
| 2568 | 15년 전 | 1580 | ||
| 2567 | 15년 전 | 731 | ||
| 2566 |
dannykim
|
15년 전 | 742 | |
| 2565 | 15년 전 | 1414 | ||
| 2564 |
기획매니아
|
15년 전 | 1034 | |
| 2563 | 15년 전 | 1317 | ||
| 2562 | 15년 전 | 1620 | ||
| 2561 | 15년 전 | 1260 | ||
| 2560 | 15년 전 | 1344 | ||
| 2559 | 15년 전 | 718 | ||
| 2558 |
|
15년 전 | 2265 | |
| 2557 | 15년 전 | 1007 | ||
| 2556 | 15년 전 | 738 | ||
| 2555 | 15년 전 | 1081 | ||
| 2554 | 15년 전 | 791 | ||
| 2553 | 15년 전 | 2037 | ||
| 2552 | 15년 전 | 1077 | ||
| 2551 | 15년 전 | 901 | ||
| 2550 |
|
15년 전 | 992 | |
| 2549 | 15년 전 | 943 | ||
| 2548 |
|
15년 전 | 961 | |
| 2547 |
|
15년 전 | 1031 | |
| 2546 | 15년 전 | 538 | ||
| 2545 | 15년 전 | 463 | ||
| 2544 | 15년 전 | 433 | ||
| 2543 | 15년 전 | 1138 | ||
| 2542 |
|
15년 전 | 940 | |
| 2541 | 15년 전 | 789 | ||
| 2540 | 15년 전 | 787 | ||
| 2539 | 15년 전 | 1190 | ||
| 2538 | 15년 전 | 3195 | ||
| 2537 | 15년 전 | 1061 | ||
| 2536 |
|
15년 전 | 1862 | |
| 2535 | 15년 전 | 1125 | ||
| 2534 |
|
15년 전 | 945 | |
| 2533 | 15년 전 | 2589 | ||
| 2532 | 15년 전 | 1592 | ||
| 2531 |
|
15년 전 | 2496 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기