<?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년 전 | 116 | ||
| 8229 | 9년 전 | 110 | ||
| 8228 |
커네드커네드
|
9년 전 | 154 | |
| 8227 | 9년 전 | 197 | ||
| 8226 | 9년 전 | 210 | ||
| 8225 | 9년 전 | 193 | ||
| 8224 | 9년 전 | 185 | ||
| 8223 | 9년 전 | 163 | ||
| 8222 |
|
9년 전 | 241 | |
| 8221 | 9년 전 | 145 | ||
| 8220 | 9년 전 | 184 | ||
| 8219 | 9년 전 | 140 | ||
| 8218 | 9년 전 | 189 | ||
| 8217 |
star3840
|
9년 전 | 159 | |
| 8216 | 9년 전 | 225 | ||
| 8215 | 9년 전 | 177 | ||
| 8214 | 9년 전 | 274 | ||
| 8213 | 9년 전 | 224 | ||
| 8212 | 9년 전 | 140 | ||
| 8211 | 9년 전 | 312 | ||
| 8210 | 9년 전 | 320 | ||
| 8209 | 9년 전 | 391 | ||
| 8208 | 9년 전 | 282 | ||
| 8207 | 9년 전 | 284 | ||
| 8206 |
|
9년 전 | 242 | |
| 8205 | 9년 전 | 225 | ||
| 8204 | 9년 전 | 196 | ||
| 8203 | 9년 전 | 272 | ||
| 8202 | 9년 전 | 192 | ||
| 8201 | 9년 전 | 235 | ||
| 8200 | 9년 전 | 232 | ||
| 8199 | 9년 전 | 257 | ||
| 8198 | 9년 전 | 221 | ||
| 8197 | 9년 전 | 212 | ||
| 8196 | 9년 전 | 611 | ||
| 8195 | 9년 전 | 213 | ||
| 8194 | 9년 전 | 328 | ||
| 8193 | 9년 전 | 220 | ||
| 8192 | 9년 전 | 250 | ||
| 8191 | 9년 전 | 203 | ||
| 8190 | 9년 전 | 202 | ||
| 8189 | 9년 전 | 254 | ||
| 8188 | 9년 전 | 192 | ||
| 8187 | 9년 전 | 193 | ||
| 8186 | 9년 전 | 195 | ||
| 8185 | 9년 전 | 367 | ||
| 8184 | 9년 전 | 151 | ||
| 8183 | 9년 전 | 376 | ||
| 8182 | 9년 전 | 224 | ||
| 8181 | 9년 전 | 187 | ||
| 8180 | 9년 전 | 766 | ||
| 8179 | 9년 전 | 535 | ||
| 8178 | 9년 전 | 380 | ||
| 8177 |
kiplayer
|
9년 전 | 390 | |
| 8176 | 9년 전 | 421 | ||
| 8175 | 9년 전 | 293 | ||
| 8174 | 9년 전 | 297 | ||
| 8173 | 9년 전 | 388 | ||
| 8172 | 9년 전 | 255 | ||
| 8171 | 9년 전 | 232 | ||
| 8170 | 9년 전 | 350 | ||
| 8169 |
커네드커네드
|
9년 전 | 305 | |
| 8168 | 9년 전 | 378 | ||
| 8167 | 9년 전 | 373 | ||
| 8166 | 9년 전 | 281 | ||
| 8165 | 9년 전 | 219 | ||
| 8164 | 9년 전 | 361 | ||
| 8163 | 9년 전 | 348 | ||
| 8162 | 9년 전 | 355 | ||
| 8161 | 9년 전 | 367 | ||
| 8160 |
|
9년 전 | 560 | |
| 8159 | 9년 전 | 503 | ||
| 8158 | 9년 전 | 313 | ||
| 8157 | 9년 전 | 427 | ||
| 8156 | 9년 전 | 311 | ||
| 8155 | 9년 전 | 306 | ||
| 8154 |
00년생용띠
|
9년 전 | 643 | |
| 8153 | 9년 전 | 282 | ||
| 8152 |
|
9년 전 | 466 | |
| 8151 | 9년 전 | 463 | ||
| 8150 | 9년 전 | 568 | ||
| 8149 |
Jangfolk
|
9년 전 | 412 | |
| 8148 | 9년 전 | 235 | ||
| 8147 | 9년 전 | 432 | ||
| 8146 | 9년 전 | 508 | ||
| 8145 | 9년 전 | 462 | ||
| 8144 | 9년 전 | 423 | ||
| 8143 | 9년 전 | 255 | ||
| 8142 | 9년 전 | 482 | ||
| 8141 | 9년 전 | 429 | ||
| 8140 | 9년 전 | 977 | ||
| 8139 | 9년 전 | 330 | ||
| 8138 |
전갈자리남자
|
9년 전 | 436 | |
| 8137 | 9년 전 | 467 | ||
| 8136 | 9년 전 | 801 | ||
| 8135 |
|
9년 전 | 836 | |
| 8134 |
PlayPixel
|
9년 전 | 577 | |
| 8133 |
|
9년 전 | 494 | |
| 8132 | 9년 전 | 512 | ||
| 8131 | 9년 전 | 877 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기