<?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);
?>
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 4830 |
임페리얼웹
|
13년 전 | 1362 | |
| 4829 |
임페리얼웹
|
13년 전 | 718 | |
| 4828 | 13년 전 | 3477 | ||
| 4827 |
|
13년 전 | 1235 | |
| 4826 | 13년 전 | 2740 | ||
| 4825 | 13년 전 | 1079 | ||
| 4824 |
gnuskin쩜net
|
13년 전 | 769 | |
| 4823 | 13년 전 | 818 | ||
| 4822 |
visualp
|
13년 전 | 682 | |
| 4821 |
다케미카코
|
13년 전 | 1260 | |
| 4820 | 13년 전 | 1346 | ||
| 4819 | 13년 전 | 2662 | ||
| 4818 |
크라이스트
|
13년 전 | 4236 | |
| 4817 |
임페리얼웹
|
13년 전 | 711 | |
| 4816 | 13년 전 | 3259 | ||
| 4815 |
하모니칼수
|
13년 전 | 649 | |
| 4814 | 13년 전 | 1109 | ||
| 4813 | 13년 전 | 708 | ||
| 4812 |
임페리얼웹
|
13년 전 | 1085 | |
| 4811 |
임페리얼웹
|
13년 전 | 1833 | |
| 4810 | 13년 전 | 1146 | ||
| 4809 | 13년 전 | 625 | ||
| 4808 | 13년 전 | 1279 | ||
| 4807 |
너는나의봄이다
|
13년 전 | 896 | |
| 4806 | 13년 전 | 1293 | ||
| 4805 | 13년 전 | 1773 | ||
| 4804 | 13년 전 | 1071 | ||
| 4803 |
한번잘해보자
|
13년 전 | 717 | |
| 4802 | 13년 전 | 1904 | ||
| 4801 |
꼬꼬아부지
|
13년 전 | 1184 | |
| 4800 | 13년 전 | 776 | ||
| 4799 |
|
13년 전 | 722 | |
| 4798 | 13년 전 | 1071 | ||
| 4797 |
한번잘해보자
|
13년 전 | 610 | |
| 4796 | 13년 전 | 1720 | ||
| 4795 | 13년 전 | 997 | ||
| 4794 |
|
13년 전 | 1017 | |
| 4793 |
|
13년 전 | 653 | |
| 4792 | 13년 전 | 1289 | ||
| 4791 | 13년 전 | 2098 | ||
| 4790 |
|
13년 전 | 620 | |
| 4789 |
한번잘해보자
|
13년 전 | 512 | |
| 4788 |
|
13년 전 | 685 | |
| 4787 | 13년 전 | 3283 | ||
| 4786 |
한번잘해보자
|
13년 전 | 756 | |
| 4785 | 13년 전 | 1304 | ||
| 4784 | 13년 전 | 1076 | ||
| 4783 |
|
13년 전 | 719 | |
| 4782 | 13년 전 | 7732 | ||
| 4781 |
크라운엠버서더
|
13년 전 | 1105 | |
| 4780 | 13년 전 | 1753 | ||
| 4779 | 13년 전 | 753 | ||
| 4778 | 13년 전 | 1088 | ||
| 4777 | 13년 전 | 916 | ||
| 4776 | 13년 전 | 1887 | ||
| 4775 | 13년 전 | 3318 | ||
| 4774 | 13년 전 | 1533 | ||
| 4773 | 13년 전 | 3238 | ||
| 4772 | 13년 전 | 1413 | ||
| 4771 | 13년 전 | 3858 | ||
| 4770 | 13년 전 | 1421 | ||
| 4769 | 13년 전 | 908 | ||
| 4768 | 13년 전 | 1881 | ||
| 4767 | 13년 전 | 2657 | ||
| 4766 | 13년 전 | 1569 | ||
| 4765 | 13년 전 | 1378 | ||
| 4764 | 13년 전 | 3139 | ||
| 4763 | 13년 전 | 1162 | ||
| 4762 |
|
13년 전 | 719 | |
| 4761 | 13년 전 | 1609 | ||
| 4760 | 13년 전 | 849 | ||
| 4759 |
NTYPE
|
13년 전 | 5175 | |
| 4758 |
프로프리랜서
|
13년 전 | 827 | |
| 4757 |
프로프리랜서
|
13년 전 | 1213 | |
| 4756 | 13년 전 | 812 | ||
| 4755 |
원시인교주
|
13년 전 | 837 | |
| 4754 |
there007
|
13년 전 | 953 | |
| 4753 | 13년 전 | 1765 | ||
| 4752 |
세상의중심
|
13년 전 | 1574 | |
| 4751 | 13년 전 | 1299 | ||
| 4750 | 13년 전 | 1499 | ||
| 4749 |
또다른세상
|
13년 전 | 3654 | |
| 4748 | 13년 전 | 768 | ||
| 4747 |
cula100jak
|
13년 전 | 1654 | |
| 4746 | 13년 전 | 1478 | ||
| 4745 |
|
13년 전 | 617 | |
| 4744 |
designcity
|
13년 전 | 741 | |
| 4743 | 13년 전 | 620 | ||
| 4742 |
|
13년 전 | 8356 | |
| 4741 | 13년 전 | 849 | ||
| 4740 | 13년 전 | 1654 | ||
| 4739 | 13년 전 | 1323 | ||
| 4738 |
|
13년 전 | 750 | |
| 4737 |
Xerro
|
13년 전 | 489 | |
| 4736 | 13년 전 | 3721 | ||
| 4735 |
keith
|
13년 전 | 541 | |
| 4734 |
|
13년 전 | 694 | |
| 4733 | 13년 전 | 1747 | ||
| 4732 |
|
13년 전 | 1248 | |
| 4731 |
|
13년 전 | 1296 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기