<?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);
?>
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 6130 |
gender
|
12년 전 | 1075 | |
| 6129 | 12년 전 | 1312 | ||
| 6128 |
|
12년 전 | 3458 | |
| 6127 | 12년 전 | 692 | ||
| 6126 |
|
12년 전 | 2198 | |
| 6125 |
|
12년 전 | 4877 | |
| 6124 | 12년 전 | 651 | ||
| 6123 | 12년 전 | 3836 | ||
| 6122 | 12년 전 | 1016 | ||
| 6121 | 12년 전 | 3747 | ||
| 6120 | 12년 전 | 904 | ||
| 6119 | 12년 전 | 1767 | ||
| 6118 | 12년 전 | 922 | ||
| 6117 | 12년 전 | 2146 | ||
| 6116 | 12년 전 | 7931 | ||
| 6115 | 12년 전 | 1914 | ||
| 6114 |
|
12년 전 | 1702 | |
| 6113 | 12년 전 | 1520 | ||
| 6112 | 12년 전 | 588 | ||
| 6111 | 12년 전 | 2102 | ||
| 6110 | 12년 전 | 1841 | ||
| 6109 | 12년 전 | 631 | ||
| 6108 | 12년 전 | 1196 | ||
| 6107 | 12년 전 | 614 | ||
| 6106 | 12년 전 | 899 | ||
| 6105 | 12년 전 | 1184 | ||
| 6104 | 12년 전 | 3575 | ||
| 6103 | 12년 전 | 2111 | ||
| 6102 | 12년 전 | 2300 | ||
| 6101 | 12년 전 | 3667 | ||
| 6100 | 12년 전 | 3474 | ||
| 6099 | 12년 전 | 3140 | ||
| 6098 | 12년 전 | 4014 | ||
| 6097 | 12년 전 | 1009 | ||
| 6096 | 12년 전 | 5974 | ||
| 6095 | 12년 전 | 1360 | ||
| 6094 | 12년 전 | 1215 | ||
| 6093 | 12년 전 | 3397 | ||
| 6092 | 12년 전 | 3031 | ||
| 6091 | 12년 전 | 5184 | ||
| 6090 | 12년 전 | 2696 | ||
| 6089 | 12년 전 | 3324 | ||
| 6088 | 12년 전 | 1011 | ||
| 6087 | 12년 전 | 840 | ||
| 6086 | 12년 전 | 2015 | ||
| 6085 |
|
12년 전 | 805 | |
| 6084 |
웹디자인되고파
|
12년 전 | 2213 | |
| 6083 | 12년 전 | 1502 | ||
| 6082 | 12년 전 | 1100 | ||
| 6081 | 12년 전 | 2094 | ||
| 6080 |
Stiven
|
12년 전 | 2308 | |
| 6079 |
프로프리랜서
|
12년 전 | 1310 | |
| 6078 |
프로프리랜서
|
12년 전 | 785 | |
| 6077 |
프로프리랜서
|
12년 전 | 1333 | |
| 6076 |
프로프리랜서
|
12년 전 | 823 | |
| 6075 |
프로프리랜서
|
12년 전 | 1210 | |
| 6074 | 12년 전 | 3851 | ||
| 6073 | 12년 전 | 3944 | ||
| 6072 | 12년 전 | 1367 | ||
| 6071 | 12년 전 | 6978 | ||
| 6070 | 12년 전 | 7558 | ||
| 6069 | 12년 전 | 2310 | ||
| 6068 | 12년 전 | 3864 | ||
| 6067 |
smwkd
|
12년 전 | 628 | |
| 6066 | 12년 전 | 3650 | ||
| 6065 | 12년 전 | 3477 | ||
| 6064 | 12년 전 | 2712 | ||
| 6063 | 12년 전 | 2818 | ||
| 6062 | 12년 전 | 2355 | ||
| 6061 | 12년 전 | 2266 | ||
| 6060 | 12년 전 | 5169 | ||
| 6059 | 12년 전 | 2798 | ||
| 6058 | 12년 전 | 3126 | ||
| 6057 | 12년 전 | 2252 | ||
| 6056 | 12년 전 | 6835 | ||
| 6055 | 12년 전 | 2573 | ||
| 6054 | 12년 전 | 3423 | ||
| 6053 | 12년 전 | 2317 | ||
| 6052 | 12년 전 | 4813 | ||
| 6051 | 12년 전 | 3692 | ||
| 6050 | 12년 전 | 2549 | ||
| 6049 | 12년 전 | 2229 | ||
| 6048 |
|
12년 전 | 1284 | |
| 6047 | 12년 전 | 3424 | ||
| 6046 | 12년 전 | 4085 | ||
| 6045 | 12년 전 | 3450 | ||
| 6044 | 12년 전 | 5325 | ||
| 6043 | 12년 전 | 1646 | ||
| 6042 | 12년 전 | 1267 | ||
| 6041 | 12년 전 | 5161 | ||
| 6040 | 12년 전 | 934 | ||
| 6039 | 12년 전 | 3401 | ||
| 6038 | 12년 전 | 3403 | ||
| 6037 | 12년 전 | 2988 | ||
| 6036 | 12년 전 | 3340 | ||
| 6035 | 12년 전 | 2862 | ||
| 6034 | 12년 전 | 2842 | ||
| 6033 | 12년 전 | 2862 | ||
| 6032 | 12년 전 | 2853 | ||
| 6031 | 12년 전 | 2874 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기