<?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);
?>
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 730 |
|
19년 전 | 2753 | |
| 729 |
그레이스웹
|
19년 전 | 3538 | |
| 728 |
|
19년 전 | 2724 | |
| 727 |
|
19년 전 | 2553 | |
| 726 |
|
19년 전 | 2372 | |
| 725 |
|
19년 전 | 2284 | |
| 724 |
|
19년 전 | 2160 | |
| 723 |
|
19년 전 | 4277 | |
| 722 |
|
19년 전 | 2704 | |
| 721 |
|
19년 전 | 2202 | |
| 720 |
|
19년 전 | 2299 | |
| 719 |
|
19년 전 | 2867 | |
| 718 |
|
19년 전 | 1981 | |
| 717 |
|
19년 전 | 3209 | |
| 716 |
|
19년 전 | 2777 | |
| 715 |
|
19년 전 | 2306 | |
| 714 |
|
19년 전 | 1851 | |
| 713 |
|
19년 전 | 2273 | |
| 712 |
|
19년 전 | 2025 | |
| 711 |
|
19년 전 | 1925 | |
| 710 |
|
19년 전 | 2502 | |
| 709 |
|
19년 전 | 2359 | |
| 708 |
|
19년 전 | 3914 | |
| 707 |
|
19년 전 | 3753 | |
| 706 |
|
19년 전 | 2265 | |
| 705 |
|
19년 전 | 3342 | |
| 704 |
|
19년 전 | 2018 | |
| 703 |
|
19년 전 | 2409 | |
| 702 |
|
19년 전 | 2302 | |
| 701 |
홀로남은자
|
19년 전 | 2369 | |
| 700 |
홀로남은자
|
19년 전 | 2191 | |
| 699 | 19년 전 | 2833 | ||
| 698 |
|
19년 전 | 2854 | |
| 697 |
|
19년 전 | 3192 | |
| 696 |
|
19년 전 | 3060 | |
| 695 |
|
19년 전 | 2734 | |
| 694 |
|
19년 전 | 2961 | |
| 693 |
|
19년 전 | 3217 | |
| 692 |
|
19년 전 | 2900 | |
| 691 |
|
19년 전 | 2653 | |
| 690 | 19년 전 | 2955 | ||
| 689 | 19년 전 | 4531 | ||
| 688 | 19년 전 | 2458 | ||
| 687 | 19년 전 | 2481 | ||
| 686 | 19년 전 | 3508 | ||
| 685 | 19년 전 | 3196 | ||
| 684 | 19년 전 | 2873 | ||
| 683 | 19년 전 | 2085 | ||
| 682 | 19년 전 | 1790 | ||
| 681 | 19년 전 | 2888 | ||
| 680 | 19년 전 | 1743 | ||
| 679 | 19년 전 | 2327 | ||
| 678 | 19년 전 | 3979 | ||
| 677 | 19년 전 | 3774 | ||
| 676 | 19년 전 | 3495 | ||
| 675 | 19년 전 | 3424 | ||
| 674 |
|
19년 전 | 1585 | |
| 673 |
|
19년 전 | 1950 | |
| 672 |
|
19년 전 | 1877 | |
| 671 | 19년 전 | 2542 | ||
| 670 | 19년 전 | 4668 | ||
| 669 |
|
19년 전 | 2788 | |
| 668 |
|
19년 전 | 1939 | |
| 667 |
|
19년 전 | 1961 | |
| 666 |
|
19년 전 | 1864 | |
| 665 |
|
19년 전 | 2603 | |
| 664 |
|
19년 전 | 8207 | |
| 663 |
|
19년 전 | 2753 | |
| 662 |
|
19년 전 | 2805 | |
| 661 |
|
19년 전 | 3069 | |
| 660 |
|
19년 전 | 2248 | |
| 659 |
|
19년 전 | 2273 | |
| 658 |
|
19년 전 | 2200 | |
| 657 |
|
19년 전 | 2101 | |
| 656 |
|
19년 전 | 2295 | |
| 655 |
|
19년 전 | 2553 | |
| 654 |
|
19년 전 | 3092 | |
| 653 | 19년 전 | 2348 | ||
| 652 | 19년 전 | 1932 | ||
| 651 |
|
19년 전 | 2875 | |
| 650 | 19년 전 | 5035 | ||
| 649 | 19년 전 | 3535 | ||
| 648 | 19년 전 | 3487 | ||
| 647 | 19년 전 | 2996 | ||
| 646 | 19년 전 | 2434 | ||
| 645 | 19년 전 | 1514 | ||
| 644 | 19년 전 | 3159 | ||
| 643 | 19년 전 | 2029 | ||
| 642 |
|
19년 전 | 5412 | |
| 641 | 19년 전 | 2450 | ||
| 640 | 19년 전 | 3449 | ||
| 639 | 19년 전 | 2891 | ||
| 638 | 19년 전 | 1774 | ||
| 637 | 19년 전 | 3892 | ||
| 636 | 19년 전 | 2441 | ||
| 635 | 19년 전 | 2332 | ||
| 634 |
|
19년 전 | 3029 | |
| 633 |
|
19년 전 | 3320 | |
| 632 | 19년 전 | 2527 | ||
| 631 | 19년 전 | 2286 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기