<?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);
?>
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 7330 | 11년 전 | 1680 | ||
| 7329 | 11년 전 | 934 | ||
| 7328 | 11년 전 | 2223 | ||
| 7327 | 11년 전 | 1723 | ||
| 7326 | 11년 전 | 3810 | ||
| 7325 | 11년 전 | 2265 | ||
| 7324 | 11년 전 | 4517 | ||
| 7323 |
호식이와미돌
|
11년 전 | 1287 | |
| 7322 |
호식이와미돌
|
11년 전 | 1142 | |
| 7321 | 11년 전 | 1787 | ||
| 7320 | 11년 전 | 1759 | ||
| 7319 | 11년 전 | 1320 | ||
| 7318 |
|
11년 전 | 977 | |
| 7317 |
멋진남자임
|
11년 전 | 1618 | |
| 7316 |
잘살아보자
|
11년 전 | 987 | |
| 7315 | 11년 전 | 1100 | ||
| 7314 | 11년 전 | 1320 | ||
| 7313 |
잘살아보자
|
11년 전 | 1120 | |
| 7312 | 11년 전 | 882 | ||
| 7311 |
사랑한데이
|
11년 전 | 2069 | |
| 7310 |
잘살아보자
|
11년 전 | 1880 | |
| 7309 |
잘살아보자
|
11년 전 | 3044 | |
| 7308 |
잘살아보자
|
11년 전 | 1018 | |
| 7307 |
잘살아보자
|
11년 전 | 782 | |
| 7306 | 11년 전 | 870 | ||
| 7305 |
잘살아보자
|
11년 전 | 2754 | |
| 7304 | 11년 전 | 1022 | ||
| 7303 | 11년 전 | 1223 | ||
| 7302 | 11년 전 | 728 | ||
| 7301 | 11년 전 | 1514 | ||
| 7300 |
mijaya
|
11년 전 | 1498 | |
| 7299 | 11년 전 | 912 | ||
| 7298 | 11년 전 | 1092 | ||
| 7297 | 11년 전 | 767 | ||
| 7296 | 11년 전 | 734 | ||
| 7295 | 11년 전 | 1553 | ||
| 7294 | 11년 전 | 903 | ||
| 7293 | 11년 전 | 809 | ||
| 7292 | 11년 전 | 910 | ||
| 7291 |
잘살아보자
|
11년 전 | 1093 | |
| 7290 |
잘살아보자
|
11년 전 | 748 | |
| 7289 | 11년 전 | 798 | ||
| 7288 |
잘살아보자
|
11년 전 | 1320 | |
| 7287 | 11년 전 | 831 | ||
| 7286 |
잘살아보자
|
11년 전 | 1331 | |
| 7285 | 11년 전 | 825 | ||
| 7284 | 11년 전 | 981 | ||
| 7283 | 11년 전 | 1007 | ||
| 7282 | 11년 전 | 770 | ||
| 7281 | 11년 전 | 800 | ||
| 7280 | 11년 전 | 1031 | ||
| 7279 | 11년 전 | 1966 | ||
| 7278 | 11년 전 | 804 | ||
| 7277 | 11년 전 | 814 | ||
| 7276 | 11년 전 | 752 | ||
| 7275 | 11년 전 | 1171 | ||
| 7274 | 11년 전 | 814 | ||
| 7273 | 11년 전 | 726 | ||
| 7272 | 11년 전 | 1053 | ||
| 7271 | 11년 전 | 1386 | ||
| 7270 | 11년 전 | 1013 | ||
| 7269 | 11년 전 | 936 | ||
| 7268 | 11년 전 | 982 | ||
| 7267 | 11년 전 | 1818 | ||
| 7266 | 11년 전 | 881 | ||
| 7265 | 11년 전 | 945 | ||
| 7264 |
잘살아보자
|
11년 전 | 2715 | |
| 7263 |
잘살아보자
|
11년 전 | 2259 | |
| 7262 |
잘살아보자
|
11년 전 | 1139 | |
| 7261 |
잘살아보자
|
11년 전 | 1632 | |
| 7260 |
잘살아보자
|
11년 전 | 1251 | |
| 7259 | 11년 전 | 1165 | ||
| 7258 |
잘살아보자
|
11년 전 | 1296 | |
| 7257 |
잘살아보자
|
11년 전 | 1894 | |
| 7256 | 11년 전 | 933 | ||
| 7255 |
그누5입문
|
11년 전 | 1945 | |
| 7254 | 11년 전 | 2163 | ||
| 7253 |
|
11년 전 | 862 | |
| 7252 | 11년 전 | 1006 | ||
| 7251 | 11년 전 | 716 | ||
| 7250 | 11년 전 | 1685 | ||
| 7249 | 11년 전 | 1547 | ||
| 7248 |
sogo87
|
11년 전 | 1039 | |
| 7247 | 11년 전 | 932 | ||
| 7246 | 11년 전 | 703 | ||
| 7245 |
잘살아보자
|
11년 전 | 1077 | |
| 7244 | 11년 전 | 1529 | ||
| 7243 |
presee
|
11년 전 | 594 | |
| 7242 |
sogo87
|
11년 전 | 785 | |
| 7241 | 11년 전 | 882 | ||
| 7240 |
브라이언2
|
11년 전 | 893 | |
| 7239 |
|
11년 전 | 1106 | |
| 7238 | 11년 전 | 2619 | ||
| 7237 |
잘살아보자
|
11년 전 | 2275 | |
| 7236 |
dethos79
|
11년 전 | 1841 | |
| 7235 |
멋진남자임
|
11년 전 | 1404 | |
| 7234 | 11년 전 | 1343 | ||
| 7233 | 11년 전 | 2315 | ||
| 7232 | 11년 전 | 1587 | ||
| 7231 | 11년 전 | 2782 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기