<?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년 전 | 72 | ||
| 8229 | 9년 전 | 72 | ||
| 8228 |
커네드커네드
|
9년 전 | 114 | |
| 8227 | 9년 전 | 124 | ||
| 8226 | 9년 전 | 162 | ||
| 8225 | 9년 전 | 150 | ||
| 8224 | 9년 전 | 147 | ||
| 8223 | 9년 전 | 114 | ||
| 8222 |
|
9년 전 | 187 | |
| 8221 | 9년 전 | 91 | ||
| 8220 | 9년 전 | 102 | ||
| 8219 | 9년 전 | 99 | ||
| 8218 | 9년 전 | 139 | ||
| 8217 |
star3840
|
9년 전 | 114 | |
| 8216 | 9년 전 | 162 | ||
| 8215 | 9년 전 | 113 | ||
| 8214 | 9년 전 | 227 | ||
| 8213 | 9년 전 | 160 | ||
| 8212 | 9년 전 | 82 | ||
| 8211 | 9년 전 | 243 | ||
| 8210 | 9년 전 | 244 | ||
| 8209 | 9년 전 | 336 | ||
| 8208 | 9년 전 | 217 | ||
| 8207 | 9년 전 | 226 | ||
| 8206 |
|
9년 전 | 188 | |
| 8205 | 9년 전 | 172 | ||
| 8204 | 9년 전 | 132 | ||
| 8203 | 9년 전 | 232 | ||
| 8202 | 9년 전 | 141 | ||
| 8201 | 9년 전 | 182 | ||
| 8200 | 9년 전 | 164 | ||
| 8199 | 9년 전 | 213 | ||
| 8198 | 9년 전 | 177 | ||
| 8197 | 9년 전 | 167 | ||
| 8196 | 9년 전 | 556 | ||
| 8195 | 9년 전 | 156 | ||
| 8194 | 9년 전 | 280 | ||
| 8193 | 9년 전 | 155 | ||
| 8192 | 9년 전 | 188 | ||
| 8191 | 9년 전 | 143 | ||
| 8190 | 9년 전 | 127 | ||
| 8189 | 9년 전 | 192 | ||
| 8188 | 9년 전 | 129 | ||
| 8187 | 9년 전 | 141 | ||
| 8186 | 9년 전 | 141 | ||
| 8185 | 9년 전 | 310 | ||
| 8184 | 9년 전 | 108 | ||
| 8183 | 9년 전 | 324 | ||
| 8182 | 9년 전 | 166 | ||
| 8181 | 9년 전 | 133 | ||
| 8180 | 9년 전 | 693 | ||
| 8179 | 9년 전 | 488 | ||
| 8178 | 9년 전 | 310 | ||
| 8177 |
kiplayer
|
9년 전 | 320 | |
| 8176 | 9년 전 | 355 | ||
| 8175 | 9년 전 | 220 | ||
| 8174 | 9년 전 | 243 | ||
| 8173 | 9년 전 | 342 | ||
| 8172 | 9년 전 | 195 | ||
| 8171 | 9년 전 | 184 | ||
| 8170 | 9년 전 | 298 | ||
| 8169 |
커네드커네드
|
9년 전 | 260 | |
| 8168 | 9년 전 | 320 | ||
| 8167 | 9년 전 | 321 | ||
| 8166 | 9년 전 | 237 | ||
| 8165 | 9년 전 | 166 | ||
| 8164 | 9년 전 | 303 | ||
| 8163 | 9년 전 | 285 | ||
| 8162 | 9년 전 | 299 | ||
| 8161 | 9년 전 | 297 | ||
| 8160 |
|
9년 전 | 490 | |
| 8159 | 9년 전 | 428 | ||
| 8158 | 9년 전 | 249 | ||
| 8157 | 9년 전 | 376 | ||
| 8156 | 9년 전 | 279 | ||
| 8155 | 9년 전 | 251 | ||
| 8154 |
00년생용띠
|
9년 전 | 599 | |
| 8153 | 9년 전 | 231 | ||
| 8152 |
|
9년 전 | 409 | |
| 8151 | 9년 전 | 408 | ||
| 8150 | 9년 전 | 498 | ||
| 8149 |
Jangfolk
|
9년 전 | 348 | |
| 8148 | 9년 전 | 169 | ||
| 8147 | 9년 전 | 372 | ||
| 8146 | 9년 전 | 435 | ||
| 8145 | 9년 전 | 379 | ||
| 8144 | 9년 전 | 347 | ||
| 8143 | 9년 전 | 194 | ||
| 8142 | 9년 전 | 426 | ||
| 8141 | 9년 전 | 381 | ||
| 8140 | 9년 전 | 929 | ||
| 8139 | 9년 전 | 260 | ||
| 8138 |
전갈자리남자
|
9년 전 | 388 | |
| 8137 | 9년 전 | 395 | ||
| 8136 | 9년 전 | 744 | ||
| 8135 |
|
9년 전 | 794 | |
| 8134 |
PlayPixel
|
9년 전 | 516 | |
| 8133 |
|
9년 전 | 433 | |
| 8132 | 9년 전 | 447 | ||
| 8131 | 9년 전 | 811 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기