<?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년 전 | 60 | ||
| 8229 | 9년 전 | 61 | ||
| 8228 |
커네드커네드
|
9년 전 | 107 | |
| 8227 | 9년 전 | 114 | ||
| 8226 | 9년 전 | 154 | ||
| 8225 | 9년 전 | 141 | ||
| 8224 | 9년 전 | 140 | ||
| 8223 | 9년 전 | 109 | ||
| 8222 |
|
9년 전 | 173 | |
| 8221 | 9년 전 | 80 | ||
| 8220 | 9년 전 | 90 | ||
| 8219 | 9년 전 | 93 | ||
| 8218 | 9년 전 | 127 | ||
| 8217 |
star3840
|
9년 전 | 103 | |
| 8216 | 9년 전 | 151 | ||
| 8215 | 9년 전 | 100 | ||
| 8214 | 9년 전 | 217 | ||
| 8213 | 9년 전 | 148 | ||
| 8212 | 9년 전 | 76 | ||
| 8211 | 9년 전 | 235 | ||
| 8210 | 9년 전 | 235 | ||
| 8209 | 9년 전 | 327 | ||
| 8208 | 9년 전 | 205 | ||
| 8207 | 9년 전 | 216 | ||
| 8206 |
|
9년 전 | 175 | |
| 8205 | 9년 전 | 160 | ||
| 8204 | 9년 전 | 122 | ||
| 8203 | 9년 전 | 222 | ||
| 8202 | 9년 전 | 133 | ||
| 8201 | 9년 전 | 172 | ||
| 8200 | 9년 전 | 149 | ||
| 8199 | 9년 전 | 198 | ||
| 8198 | 9년 전 | 165 | ||
| 8197 | 9년 전 | 152 | ||
| 8196 | 9년 전 | 539 | ||
| 8195 | 9년 전 | 147 | ||
| 8194 | 9년 전 | 275 | ||
| 8193 | 9년 전 | 149 | ||
| 8192 | 9년 전 | 176 | ||
| 8191 | 9년 전 | 128 | ||
| 8190 | 9년 전 | 121 | ||
| 8189 | 9년 전 | 179 | ||
| 8188 | 9년 전 | 122 | ||
| 8187 | 9년 전 | 132 | ||
| 8186 | 9년 전 | 135 | ||
| 8185 | 9년 전 | 301 | ||
| 8184 | 9년 전 | 98 | ||
| 8183 | 9년 전 | 316 | ||
| 8182 | 9년 전 | 158 | ||
| 8181 | 9년 전 | 120 | ||
| 8180 | 9년 전 | 687 | ||
| 8179 | 9년 전 | 478 | ||
| 8178 | 9년 전 | 297 | ||
| 8177 |
kiplayer
|
9년 전 | 302 | |
| 8176 | 9년 전 | 341 | ||
| 8175 | 9년 전 | 211 | ||
| 8174 | 9년 전 | 229 | ||
| 8173 | 9년 전 | 337 | ||
| 8172 | 9년 전 | 185 | ||
| 8171 | 9년 전 | 175 | ||
| 8170 | 9년 전 | 286 | ||
| 8169 |
커네드커네드
|
9년 전 | 250 | |
| 8168 | 9년 전 | 310 | ||
| 8167 | 9년 전 | 311 | ||
| 8166 | 9년 전 | 226 | ||
| 8165 | 9년 전 | 156 | ||
| 8164 | 9년 전 | 295 | ||
| 8163 | 9년 전 | 276 | ||
| 8162 | 9년 전 | 289 | ||
| 8161 | 9년 전 | 283 | ||
| 8160 |
|
9년 전 | 479 | |
| 8159 | 9년 전 | 413 | ||
| 8158 | 9년 전 | 230 | ||
| 8157 | 9년 전 | 365 | ||
| 8156 | 9년 전 | 271 | ||
| 8155 | 9년 전 | 244 | ||
| 8154 |
00년생용띠
|
9년 전 | 593 | |
| 8153 | 9년 전 | 221 | ||
| 8152 |
|
9년 전 | 395 | |
| 8151 | 9년 전 | 397 | ||
| 8150 | 9년 전 | 491 | ||
| 8149 |
Jangfolk
|
9년 전 | 333 | |
| 8148 | 9년 전 | 157 | ||
| 8147 | 9년 전 | 365 | ||
| 8146 | 9년 전 | 424 | ||
| 8145 | 9년 전 | 366 | ||
| 8144 | 9년 전 | 335 | ||
| 8143 | 9년 전 | 182 | ||
| 8142 | 9년 전 | 421 | ||
| 8141 | 9년 전 | 371 | ||
| 8140 | 9년 전 | 918 | ||
| 8139 | 9년 전 | 251 | ||
| 8138 |
전갈자리남자
|
9년 전 | 378 | |
| 8137 | 9년 전 | 380 | ||
| 8136 | 9년 전 | 735 | ||
| 8135 |
|
9년 전 | 784 | |
| 8134 |
PlayPixel
|
9년 전 | 501 | |
| 8133 |
|
9년 전 | 427 | |
| 8132 | 9년 전 | 439 | ||
| 8131 | 9년 전 | 802 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기