<?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);
?>
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 7330 | 11년 전 | 1688 | ||
| 7329 | 11년 전 | 936 | ||
| 7328 | 11년 전 | 2232 | ||
| 7327 | 11년 전 | 1725 | ||
| 7326 | 11년 전 | 3819 | ||
| 7325 | 11년 전 | 2274 | ||
| 7324 | 11년 전 | 4527 | ||
| 7323 |
호식이와미돌
|
11년 전 | 1301 | |
| 7322 |
호식이와미돌
|
11년 전 | 1150 | |
| 7321 | 11년 전 | 1788 | ||
| 7320 | 11년 전 | 1763 | ||
| 7319 | 11년 전 | 1327 | ||
| 7318 |
|
11년 전 | 985 | |
| 7317 |
멋진남자임
|
11년 전 | 1621 | |
| 7316 |
잘살아보자
|
11년 전 | 994 | |
| 7315 | 11년 전 | 1108 | ||
| 7314 | 11년 전 | 1325 | ||
| 7313 |
잘살아보자
|
11년 전 | 1129 | |
| 7312 | 11년 전 | 886 | ||
| 7311 |
사랑한데이
|
11년 전 | 2076 | |
| 7310 |
잘살아보자
|
11년 전 | 1890 | |
| 7309 |
잘살아보자
|
11년 전 | 3052 | |
| 7308 |
잘살아보자
|
11년 전 | 1022 | |
| 7307 |
잘살아보자
|
11년 전 | 785 | |
| 7306 | 11년 전 | 883 | ||
| 7305 |
잘살아보자
|
11년 전 | 2757 | |
| 7304 | 11년 전 | 1039 | ||
| 7303 | 11년 전 | 1231 | ||
| 7302 | 11년 전 | 745 | ||
| 7301 | 11년 전 | 1523 | ||
| 7300 |
mijaya
|
11년 전 | 1503 | |
| 7299 | 11년 전 | 918 | ||
| 7298 | 11년 전 | 1099 | ||
| 7297 | 11년 전 | 770 | ||
| 7296 | 11년 전 | 742 | ||
| 7295 | 11년 전 | 1566 | ||
| 7294 | 11년 전 | 916 | ||
| 7293 | 11년 전 | 816 | ||
| 7292 | 11년 전 | 910 | ||
| 7291 |
잘살아보자
|
11년 전 | 1096 | |
| 7290 |
잘살아보자
|
11년 전 | 760 | |
| 7289 | 11년 전 | 807 | ||
| 7288 |
잘살아보자
|
11년 전 | 1328 | |
| 7287 | 11년 전 | 839 | ||
| 7286 |
잘살아보자
|
11년 전 | 1336 | |
| 7285 | 11년 전 | 830 | ||
| 7284 | 11년 전 | 986 | ||
| 7283 | 11년 전 | 1012 | ||
| 7282 | 11년 전 | 776 | ||
| 7281 | 11년 전 | 810 | ||
| 7280 | 11년 전 | 1042 | ||
| 7279 | 11년 전 | 1974 | ||
| 7278 | 11년 전 | 814 | ||
| 7277 | 11년 전 | 820 | ||
| 7276 | 11년 전 | 762 | ||
| 7275 | 11년 전 | 1183 | ||
| 7274 | 11년 전 | 824 | ||
| 7273 | 11년 전 | 742 | ||
| 7272 | 11년 전 | 1059 | ||
| 7271 | 11년 전 | 1395 | ||
| 7270 | 11년 전 | 1023 | ||
| 7269 | 11년 전 | 951 | ||
| 7268 | 11년 전 | 991 | ||
| 7267 | 11년 전 | 1830 | ||
| 7266 | 11년 전 | 893 | ||
| 7265 | 11년 전 | 951 | ||
| 7264 |
잘살아보자
|
11년 전 | 2718 | |
| 7263 |
잘살아보자
|
11년 전 | 2264 | |
| 7262 |
잘살아보자
|
11년 전 | 1142 | |
| 7261 |
잘살아보자
|
11년 전 | 1635 | |
| 7260 |
잘살아보자
|
11년 전 | 1255 | |
| 7259 | 11년 전 | 1168 | ||
| 7258 |
잘살아보자
|
11년 전 | 1302 | |
| 7257 |
잘살아보자
|
11년 전 | 1896 | |
| 7256 | 11년 전 | 943 | ||
| 7255 |
그누5입문
|
11년 전 | 1949 | |
| 7254 | 11년 전 | 2169 | ||
| 7253 |
|
11년 전 | 864 | |
| 7252 | 11년 전 | 1007 | ||
| 7251 | 11년 전 | 720 | ||
| 7250 | 11년 전 | 1693 | ||
| 7249 | 11년 전 | 1549 | ||
| 7248 |
sogo87
|
11년 전 | 1044 | |
| 7247 | 11년 전 | 934 | ||
| 7246 | 11년 전 | 706 | ||
| 7245 |
잘살아보자
|
11년 전 | 1083 | |
| 7244 | 11년 전 | 1532 | ||
| 7243 |
presee
|
11년 전 | 599 | |
| 7242 |
sogo87
|
11년 전 | 790 | |
| 7241 | 11년 전 | 892 | ||
| 7240 |
브라이언2
|
11년 전 | 906 | |
| 7239 |
|
11년 전 | 1120 | |
| 7238 | 11년 전 | 2624 | ||
| 7237 |
잘살아보자
|
11년 전 | 2275 | |
| 7236 |
dethos79
|
11년 전 | 1843 | |
| 7235 |
멋진남자임
|
11년 전 | 1404 | |
| 7234 | 11년 전 | 1348 | ||
| 7233 | 11년 전 | 2319 | ||
| 7232 | 11년 전 | 1599 | ||
| 7231 | 11년 전 | 2786 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기