<?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);
?>
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 8230 | 9년 전 | 77 | ||
| 8229 | 9년 전 | 74 | ||
| 8228 |
커네드커네드
|
9년 전 | 115 | |
| 8227 | 9년 전 | 124 | ||
| 8226 | 9년 전 | 165 | ||
| 8225 | 9년 전 | 151 | ||
| 8224 | 9년 전 | 150 | ||
| 8223 | 9년 전 | 115 | ||
| 8222 |
|
9년 전 | 192 | |
| 8221 | 9년 전 | 93 | ||
| 8220 | 9년 전 | 103 | ||
| 8219 | 9년 전 | 102 | ||
| 8218 | 9년 전 | 144 | ||
| 8217 |
star3840
|
9년 전 | 115 | |
| 8216 | 9년 전 | 162 | ||
| 8215 | 9년 전 | 116 | ||
| 8214 | 9년 전 | 228 | ||
| 8213 | 9년 전 | 162 | ||
| 8212 | 9년 전 | 84 | ||
| 8211 | 9년 전 | 247 | ||
| 8210 | 9년 전 | 249 | ||
| 8209 | 9년 전 | 338 | ||
| 8208 | 9년 전 | 220 | ||
| 8207 | 9년 전 | 230 | ||
| 8206 |
|
9년 전 | 194 | |
| 8205 | 9년 전 | 174 | ||
| 8204 | 9년 전 | 135 | ||
| 8203 | 9년 전 | 234 | ||
| 8202 | 9년 전 | 147 | ||
| 8201 | 9년 전 | 184 | ||
| 8200 | 9년 전 | 167 | ||
| 8199 | 9년 전 | 217 | ||
| 8198 | 9년 전 | 180 | ||
| 8197 | 9년 전 | 167 | ||
| 8196 | 9년 전 | 557 | ||
| 8195 | 9년 전 | 159 | ||
| 8194 | 9년 전 | 284 | ||
| 8193 | 9년 전 | 157 | ||
| 8192 | 9년 전 | 198 | ||
| 8191 | 9년 전 | 144 | ||
| 8190 | 9년 전 | 131 | ||
| 8189 | 9년 전 | 195 | ||
| 8188 | 9년 전 | 131 | ||
| 8187 | 9년 전 | 143 | ||
| 8186 | 9년 전 | 146 | ||
| 8185 | 9년 전 | 314 | ||
| 8184 | 9년 전 | 109 | ||
| 8183 | 9년 전 | 325 | ||
| 8182 | 9년 전 | 170 | ||
| 8181 | 9년 전 | 135 | ||
| 8180 | 9년 전 | 694 | ||
| 8179 | 9년 전 | 488 | ||
| 8178 | 9년 전 | 313 | ||
| 8177 |
kiplayer
|
9년 전 | 326 | |
| 8176 | 9년 전 | 356 | ||
| 8175 | 9년 전 | 223 | ||
| 8174 | 9년 전 | 248 | ||
| 8173 | 9년 전 | 346 | ||
| 8172 | 9년 전 | 198 | ||
| 8171 | 9년 전 | 185 | ||
| 8170 | 9년 전 | 298 | ||
| 8169 |
커네드커네드
|
9년 전 | 261 | |
| 8168 | 9년 전 | 322 | ||
| 8167 | 9년 전 | 323 | ||
| 8166 | 9년 전 | 239 | ||
| 8165 | 9년 전 | 169 | ||
| 8164 | 9년 전 | 306 | ||
| 8163 | 9년 전 | 290 | ||
| 8162 | 9년 전 | 306 | ||
| 8161 | 9년 전 | 298 | ||
| 8160 |
|
9년 전 | 493 | |
| 8159 | 9년 전 | 431 | ||
| 8158 | 9년 전 | 255 | ||
| 8157 | 9년 전 | 381 | ||
| 8156 | 9년 전 | 279 | ||
| 8155 | 9년 전 | 256 | ||
| 8154 |
00년생용띠
|
9년 전 | 602 | |
| 8153 | 9년 전 | 236 | ||
| 8152 |
|
9년 전 | 413 | |
| 8151 | 9년 전 | 409 | ||
| 8150 | 9년 전 | 500 | ||
| 8149 |
Jangfolk
|
9년 전 | 351 | |
| 8148 | 9년 전 | 171 | ||
| 8147 | 9년 전 | 377 | ||
| 8146 | 9년 전 | 437 | ||
| 8145 | 9년 전 | 381 | ||
| 8144 | 9년 전 | 348 | ||
| 8143 | 9년 전 | 195 | ||
| 8142 | 9년 전 | 428 | ||
| 8141 | 9년 전 | 385 | ||
| 8140 | 9년 전 | 929 | ||
| 8139 | 9년 전 | 263 | ||
| 8138 |
전갈자리남자
|
9년 전 | 389 | |
| 8137 | 9년 전 | 398 | ||
| 8136 | 9년 전 | 749 | ||
| 8135 |
|
9년 전 | 796 | |
| 8134 |
PlayPixel
|
9년 전 | 519 | |
| 8133 |
|
9년 전 | 439 | |
| 8132 | 9년 전 | 454 | ||
| 8131 | 9년 전 | 813 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기