<?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);
?>
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 7030 | 11년 전 | 1420 | ||
| 7029 |
|
11년 전 | 3250 | |
| 7028 |
|
11년 전 | 1146 | |
| 7027 | 11년 전 | 1014 | ||
| 7026 | 11년 전 | 2090 | ||
| 7025 |
어려워요잉
|
11년 전 | 2745 | |
| 7024 | 11년 전 | 2107 | ||
| 7023 | 11년 전 | 3142 | ||
| 7022 |
Shhhh
|
11년 전 | 1539 | |
| 7021 |
|
11년 전 | 3286 | |
| 7020 | 11년 전 | 796 | ||
| 7019 |
막돼먹은영애
|
11년 전 | 1088 | |
| 7018 | 11년 전 | 1965 | ||
| 7017 | 11년 전 | 2327 | ||
| 7016 | 11년 전 | 1034 | ||
| 7015 | 11년 전 | 2835 | ||
| 7014 | 11년 전 | 3033 | ||
| 7013 | 11년 전 | 1520 | ||
| 7012 |
|
11년 전 | 2199 | |
| 7011 | 11년 전 | 1050 | ||
| 7010 | 11년 전 | 1407 | ||
| 7009 |
|
11년 전 | 1084 | |
| 7008 | 11년 전 | 2272 | ||
| 7007 | 11년 전 | 2193 | ||
| 7006 |
|
11년 전 | 1182 | |
| 7005 | 11년 전 | 5314 | ||
| 7004 | 11년 전 | 2365 | ||
| 7003 | 11년 전 | 3080 | ||
| 7002 | 11년 전 | 1930 | ||
| 7001 | 11년 전 | 980 | ||
| 7000 | 11년 전 | 2052 | ||
| 6999 |
|
11년 전 | 2176 | |
| 6998 | 11년 전 | 1890 | ||
| 6997 |
네이비칼라
|
11년 전 | 1501 | |
| 6996 | 11년 전 | 960 | ||
| 6995 |
|
11년 전 | 1863 | |
| 6994 | 11년 전 | 2580 | ||
| 6993 |
kimsdesign
|
11년 전 | 1305 | |
| 6992 |
|
11년 전 | 2778 | |
| 6991 | 11년 전 | 1723 | ||
| 6990 | 11년 전 | 4481 | ||
| 6989 | 11년 전 | 1863 | ||
| 6988 |
네이비컬러
|
11년 전 | 2526 | |
| 6987 | 11년 전 | 3734 | ||
| 6986 |
잘살아보자
|
11년 전 | 1598 | |
| 6985 |
잘살아보자
|
11년 전 | 2483 | |
| 6984 | 11년 전 | 831 | ||
| 6983 |
천재조상훈
|
11년 전 | 1878 | |
| 6982 |
천재조상훈
|
11년 전 | 4510 | |
| 6981 |
천재조상훈
|
11년 전 | 1638 | |
| 6980 |
|
11년 전 | 1890 | |
| 6979 |
|
11년 전 | 763 | |
| 6978 |
잘살아보자
|
11년 전 | 1152 | |
| 6977 |
잘살아보자
|
11년 전 | 1475 | |
| 6976 |
잘살아보자
|
11년 전 | 1583 | |
| 6975 |
천재조상훈
|
11년 전 | 1491 | |
| 6974 |
잘살아보자
|
11년 전 | 2235 | |
| 6973 |
잘살아보자
|
11년 전 | 1163 | |
| 6972 |
잘살아보자
|
11년 전 | 3074 | |
| 6971 |
잘살아보자
|
11년 전 | 3280 | |
| 6970 |
잘살아보자
|
11년 전 | 1851 | |
| 6969 |
잘살아보자
|
11년 전 | 4787 | |
| 6968 | 11년 전 | 9914 | ||
| 6967 |
|
11년 전 | 2644 | |
| 6966 |
|
11년 전 | 1119 | |
| 6965 | 11년 전 | 3265 | ||
| 6964 | 11년 전 | 2587 | ||
| 6963 | 11년 전 | 2108 | ||
| 6962 |
star3840
|
11년 전 | 1022 | |
| 6961 | 11년 전 | 4248 | ||
| 6960 |
|
11년 전 | 738 | |
| 6959 | 11년 전 | 1262 | ||
| 6958 |
|
11년 전 | 1681 | |
| 6957 | 11년 전 | 1907 | ||
| 6956 |
잘살아보자
|
11년 전 | 1857 | |
| 6955 | 11년 전 | 4631 | ||
| 6954 | 11년 전 | 1634 | ||
| 6953 |
잘살아보자
|
11년 전 | 883 | |
| 6952 |
잘살아보자
|
11년 전 | 2053 | |
| 6951 | 11년 전 | 1617 | ||
| 6950 | 11년 전 | 2618 | ||
| 6949 |
잘살아보자
|
11년 전 | 891 | |
| 6948 | 11년 전 | 1564 | ||
| 6947 | 11년 전 | 1473 | ||
| 6946 | 11년 전 | 1621 | ||
| 6945 | 11년 전 | 1231 | ||
| 6944 | 11년 전 | 1193 | ||
| 6943 | 11년 전 | 1236 | ||
| 6942 | 11년 전 | 1592 | ||
| 6941 | 11년 전 | 1664 | ||
| 6940 | 11년 전 | 1759 | ||
| 6939 | 11년 전 | 1672 | ||
| 6938 | 11년 전 | 1952 | ||
| 6937 | 11년 전 | 1158 | ||
| 6936 | 11년 전 | 1363 | ||
| 6935 | 11년 전 | 1308 | ||
| 6934 | 11년 전 | 1474 | ||
| 6933 | 11년 전 | 1983 | ||
| 6932 | 11년 전 | 1544 | ||
| 6931 | 11년 전 | 1549 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기