<?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);
?>
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 5330 | 13년 전 | 770 | ||
| 5329 | 13년 전 | 706 | ||
| 5328 | 13년 전 | 639 | ||
| 5327 | 13년 전 | 882 | ||
| 5326 |
downmix
|
13년 전 | 1118 | |
| 5325 |
techer
|
13년 전 | 3141 | |
| 5324 |
techer
|
13년 전 | 968 | |
| 5323 | 13년 전 | 1175 | ||
| 5322 |
김준수사랑
|
13년 전 | 892 | |
| 5321 |
다케미카코
|
13년 전 | 754 | |
| 5320 |
|
13년 전 | 996 | |
| 5319 |
한번잘해보자
|
13년 전 | 1006 | |
| 5318 |
|
13년 전 | 1273 | |
| 5317 |
techer
|
13년 전 | 2705 | |
| 5316 |
techer
|
13년 전 | 3144 | |
| 5315 | 13년 전 | 1173 | ||
| 5314 |
티즈코리아
|
13년 전 | 1227 | |
| 5313 | 13년 전 | 704 | ||
| 5312 |
|
13년 전 | 1873 | |
| 5311 |
innis
|
13년 전 | 772 | |
| 5310 | 13년 전 | 857 | ||
| 5309 |
changho
|
13년 전 | 660 | |
| 5308 |
|
13년 전 | 1364 | |
| 5307 |
|
13년 전 | 801 | |
| 5306 | 13년 전 | 1183 | ||
| 5305 |
세상속으로
|
13년 전 | 1164 | |
| 5304 | 13년 전 | 666 | ||
| 5303 | 13년 전 | 2258 | ||
| 5302 | 13년 전 | 1394 | ||
| 5301 | 13년 전 | 1107 | ||
| 5300 |
프로프리랜서
|
13년 전 | 1085 | |
| 5299 | 13년 전 | 874 | ||
| 5298 | 13년 전 | 681 | ||
| 5297 |
나랑사귈래
|
13년 전 | 610 | |
| 5296 | 13년 전 | 1338 | ||
| 5295 | 13년 전 | 1120 | ||
| 5294 | 13년 전 | 729 | ||
| 5293 |
|
13년 전 | 5820 | |
| 5292 |
|
13년 전 | 792 | |
| 5291 | 13년 전 | 615 | ||
| 5290 | 13년 전 | 554 | ||
| 5289 | 13년 전 | 654 | ||
| 5288 | 13년 전 | 1172 | ||
| 5287 | 13년 전 | 762 | ||
| 5286 | 13년 전 | 973 | ||
| 5285 | 13년 전 | 1325 | ||
| 5284 |
미스홍당무
|
13년 전 | 859 | |
| 5283 |
basketball
|
13년 전 | 1762 | |
| 5282 | 13년 전 | 789 | ||
| 5281 |
|
13년 전 | 802 | |
| 5280 | 13년 전 | 1214 | ||
| 5279 | 13년 전 | 1385 | ||
| 5278 |
크라이스트
|
13년 전 | 2050 | |
| 5277 |
|
13년 전 | 732 | |
| 5276 |
그누보드환자이송
|
13년 전 | 789 | |
| 5275 | 13년 전 | 704 | ||
| 5274 | 13년 전 | 1374 | ||
| 5273 | 13년 전 | 2004 | ||
| 5272 | 13년 전 | 1120 | ||
| 5271 | 13년 전 | 1434 | ||
| 5270 | 13년 전 | 808 | ||
| 5269 | 13년 전 | 525 | ||
| 5268 | 13년 전 | 662 | ||
| 5267 | 13년 전 | 1190 | ||
| 5266 | 13년 전 | 1857 | ||
| 5265 | 13년 전 | 1628 | ||
| 5264 |
크라이스트
|
13년 전 | 1207 | |
| 5263 |
|
13년 전 | 1263 | |
| 5262 |
제이티37
|
13년 전 | 585 | |
| 5261 |
|
13년 전 | 779 | |
| 5260 |
quenya
|
13년 전 | 2070 | |
| 5259 | 13년 전 | 707 | ||
| 5258 | 13년 전 | 731 | ||
| 5257 |
크라이스트
|
13년 전 | 4596 | |
| 5256 | 13년 전 | 1252 | ||
| 5255 | 13년 전 | 3262 | ||
| 5254 |
|
13년 전 | 707 | |
| 5253 | 13년 전 | 768 | ||
| 5252 | 13년 전 | 768 | ||
| 5251 | 13년 전 | 721 | ||
| 5250 |
dudn1114
|
13년 전 | 1293 | |
| 5249 | 13년 전 | 672 | ||
| 5248 | 13년 전 | 742 | ||
| 5247 | 13년 전 | 2083 | ||
| 5246 | 13년 전 | 506 | ||
| 5245 | 13년 전 | 2196 | ||
| 5244 | 13년 전 | 1458 | ||
| 5243 |
|
13년 전 | 973 | |
| 5242 | 13년 전 | 770 | ||
| 5241 | 13년 전 | 1851 | ||
| 5240 |
|
13년 전 | 506 | |
| 5239 | 13년 전 | 1035 | ||
| 5238 | 13년 전 | 1223 | ||
| 5237 | 13년 전 | 1119 | ||
| 5236 | 13년 전 | 588 | ||
| 5235 |
|
13년 전 | 766 | |
| 5234 |
뭐먹고살지ㅠ
|
13년 전 | 1033 | |
| 5233 | 13년 전 | 3597 | ||
| 5232 | 13년 전 | 3138 | ||
| 5231 | 13년 전 | 3731 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기