<?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);
?>
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 130 | 20년 전 | 3974 | ||
| 129 | 20년 전 | 2917 | ||
| 128 | 20년 전 | 3653 | ||
| 127 | 20년 전 | 3468 | ||
| 126 | 20년 전 | 3734 | ||
| 125 | 20년 전 | 8569 | ||
| 124 | 20년 전 | 2592 | ||
| 123 | 20년 전 | 3735 | ||
| 122 | 20년 전 | 3195 | ||
| 121 | 20년 전 | 2600 | ||
| 120 | 20년 전 | 2653 | ||
| 119 | 20년 전 | 2571 | ||
| 118 | 20년 전 | 2856 | ||
| 117 |
|
20년 전 | 3045 | |
| 116 | 20년 전 | 5293 | ||
| 115 | 20년 전 | 3901 | ||
| 114 | 20년 전 | 4952 | ||
| 113 | 20년 전 | 6200 | ||
| 112 | 20년 전 | 7317 | ||
| 111 | 20년 전 | 18424 | ||
| 110 | 20년 전 | 6868 | ||
| 109 | 20년 전 | 2869 | ||
| 108 | 20년 전 | 4129 | ||
| 107 |
prosper
|
20년 전 | 2481 | |
| 106 |
prosper
|
20년 전 | 4303 | |
| 105 |
아우겐나이스
|
20년 전 | 2900 | |
| 104 | 20년 전 | 2250 | ||
| 103 | 20년 전 | 2469 | ||
| 102 | 20년 전 | 2231 | ||
| 101 | 20년 전 | 2558 | ||
| 100 | 20년 전 | 1737 | ||
| 99 | 20년 전 | 1560 | ||
| 98 | 20년 전 | 1610 | ||
| 97 | 20년 전 | 2115 | ||
| 96 | 20년 전 | 1864 | ||
| 95 | 20년 전 | 2362 | ||
| 94 | 20년 전 | 3549 | ||
| 93 | 20년 전 | 1551 | ||
| 92 | 20년 전 | 1746 | ||
| 91 | 20년 전 | 3164 | ||
| 90 | 20년 전 | 2335 | ||
| 89 | 20년 전 | 3159 | ||
| 88 | 20년 전 | 2859 | ||
| 87 | 20년 전 | 3286 | ||
| 86 | 20년 전 | 5112 | ||
| 85 | 20년 전 | 2510 | ||
| 84 | 20년 전 | 4817 | ||
| 83 | 20년 전 | 2493 | ||
| 82 | 20년 전 | 3108 | ||
| 81 | 20년 전 | 7614 | ||
| 80 | 20년 전 | 3811 | ||
| 79 | 20년 전 | 3200 | ||
| 78 | 20년 전 | 4681 | ||
| 77 | 20년 전 | 2886 | ||
| 76 | 20년 전 | 6206 | ||
| 75 | 20년 전 | 4464 | ||
| 74 | 20년 전 | 5772 | ||
| 73 | 20년 전 | 3617 | ||
| 72 | 20년 전 | 5960 | ||
| 71 | 20년 전 | 3100 | ||
| 70 | 20년 전 | 2828 | ||
| 69 | 20년 전 | 2625 | ||
| 68 | 20년 전 | 2435 | ||
| 67 | 20년 전 | 2642 | ||
| 66 | 20년 전 | 2660 | ||
| 65 | 20년 전 | 3780 | ||
| 64 | 20년 전 | 2815 | ||
| 63 | 20년 전 | 2450 | ||
| 62 | 20년 전 | 2254 | ||
| 61 | 20년 전 | 3058 | ||
| 60 | 20년 전 | 3124 | ||
| 59 | 20년 전 | 2502 | ||
| 58 | 20년 전 | 2585 | ||
| 57 | 20년 전 | 2956 | ||
| 56 | 20년 전 | 2304 | ||
| 55 | 20년 전 | 2747 | ||
| 54 | 20년 전 | 2114 | ||
| 53 | 20년 전 | 2341 | ||
| 52 | 20년 전 | 2686 | ||
| 51 |
prosper
|
20년 전 | 2339 | |
| 50 |
prosper
|
20년 전 | 2157 | |
| 49 | 21년 전 | 2169 | ||
| 48 | 21년 전 | 2319 | ||
| 47 | 21년 전 | 1919 | ||
| 46 | 21년 전 | 1919 | ||
| 45 | 21년 전 | 2124 | ||
| 44 | 21년 전 | 2350 | ||
| 43 | 21년 전 | 4565 | ||
| 42 |
prosper
|
21년 전 | 2704 | |
| 41 |
prosper
|
21년 전 | 2107 | |
| 40 | 21년 전 | 2172 | ||
| 39 | 21년 전 | 2138 | ||
| 38 | 21년 전 | 2406 | ||
| 37 | 21년 전 | 2553 | ||
| 36 | 21년 전 | 1767 | ||
| 35 | 21년 전 | 4063 | ||
| 34 | 21년 전 | 3841 | ||
| 33 | 21년 전 | 2984 | ||
| 32 |
prosper
|
21년 전 | 2894 | |
| 31 | 21년 전 | 5264 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기