<?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);
?>
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 5930 | 12년 전 | 4639 | ||
| 5929 | 12년 전 | 7836 | ||
| 5928 | 12년 전 | 782 | ||
| 5927 | 12년 전 | 1412 | ||
| 5926 | 12년 전 | 1828 | ||
| 5925 |
김준수사랑
|
12년 전 | 1243 | |
| 5924 |
|
12년 전 | 2754 | |
| 5923 | 12년 전 | 956 | ||
| 5922 | 13년 전 | 1161 | ||
| 5921 | 13년 전 | 654 | ||
| 5920 | 13년 전 | 1180 | ||
| 5919 |
|
13년 전 | 1371 | |
| 5918 | 13년 전 | 12588 | ||
| 5917 |
프로프리랜서
|
13년 전 | 1098 | |
| 5916 |
프로프리랜서
|
13년 전 | 4621 | |
| 5915 |
프로프리랜서
|
13년 전 | 1600 | |
| 5914 |
프로프리랜서
|
13년 전 | 648 | |
| 5913 |
프로프리랜서
|
13년 전 | 930 | |
| 5912 |
프로프리랜서
|
13년 전 | 3744 | |
| 5911 |
프로프리랜서
|
13년 전 | 922 | |
| 5910 |
|
13년 전 | 4580 | |
| 5909 |
수야3019
|
13년 전 | 664 | |
| 5908 | 13년 전 | 832 | ||
| 5907 | 13년 전 | 1228 | ||
| 5906 | 13년 전 | 8753 | ||
| 5905 |
프로프리랜서
|
13년 전 | 1469 | |
| 5904 | 13년 전 | 2494 | ||
| 5903 | 13년 전 | 1651 | ||
| 5902 | 13년 전 | 1924 | ||
| 5901 | 13년 전 | 2009 | ||
| 5900 |
프로프리랜서
|
13년 전 | 1085 | |
| 5899 |
프로프리랜서
|
13년 전 | 1276 | |
| 5898 | 13년 전 | 17670 | ||
| 5897 | 13년 전 | 2332 | ||
| 5896 | 13년 전 | 4353 | ||
| 5895 | 13년 전 | 1687 | ||
| 5894 | 13년 전 | 2095 | ||
| 5893 |
프로프리랜서
|
13년 전 | 2154 | |
| 5892 | 13년 전 | 16039 | ||
| 5891 |
bitmaster
|
13년 전 | 1076 | |
| 5890 |
프로프리랜서
|
13년 전 | 942 | |
| 5889 |
|
13년 전 | 722 | |
| 5888 | 13년 전 | 1615 | ||
| 5887 |
|
13년 전 | 3197 | |
| 5886 | 13년 전 | 3448 | ||
| 5885 | 13년 전 | 2109 | ||
| 5884 | 13년 전 | 5651 | ||
| 5883 | 13년 전 | 2816 | ||
| 5882 | 13년 전 | 6026 | ||
| 5881 | 13년 전 | 1634 | ||
| 5880 | 13년 전 | 20713 | ||
| 5879 | 13년 전 | 897 | ||
| 5878 |
나의라임토마토
|
13년 전 | 1401 | |
| 5877 | 13년 전 | 16761 | ||
| 5876 |
maniAc
|
13년 전 | 2797 | |
| 5875 | 13년 전 | 1030 | ||
| 5874 | 13년 전 | 3730 | ||
| 5873 |
lainfox
|
13년 전 | 1181 | |
| 5872 | 13년 전 | 1343 | ||
| 5871 | 13년 전 | 793 | ||
| 5870 | 13년 전 | 2527 | ||
| 5869 |
AMDbest
|
13년 전 | 1511 | |
| 5868 |
한번잘해보자
|
13년 전 | 656 | |
| 5867 |
|
13년 전 | 908 | |
| 5866 | 13년 전 | 7487 | ||
| 5865 | 13년 전 | 2403 | ||
| 5864 | 13년 전 | 933 | ||
| 5863 | 13년 전 | 1308 | ||
| 5862 | 13년 전 | 2875 | ||
| 5861 | 13년 전 | 1026 | ||
| 5860 | 13년 전 | 19329 | ||
| 5859 | 13년 전 | 2936 | ||
| 5858 | 13년 전 | 2651 | ||
| 5857 | 13년 전 | 4820 | ||
| 5856 |
|
13년 전 | 1946 | |
| 5855 | 13년 전 | 816 | ||
| 5854 | 13년 전 | 1005 | ||
| 5853 | 13년 전 | 16102 | ||
| 5852 | 13년 전 | 823 | ||
| 5851 | 13년 전 | 2222 | ||
| 5850 | 13년 전 | 1772 | ||
| 5849 |
AMDbest
|
13년 전 | 1301 | |
| 5848 |
|
13년 전 | 1161 | |
| 5847 |
SeanLee
|
13년 전 | 1303 | |
| 5846 | 13년 전 | 23463 | ||
| 5845 | 13년 전 | 2644 | ||
| 5844 | 13년 전 | 28798 | ||
| 5843 |
|
13년 전 | 2198 | |
| 5842 | 13년 전 | 22513 | ||
| 5841 | 13년 전 | 5741 | ||
| 5840 |
Quincy
|
13년 전 | 930 | |
| 5839 | 13년 전 | 956 | ||
| 5838 | 13년 전 | 2815 | ||
| 5837 | 13년 전 | 1092 | ||
| 5836 | 13년 전 | 2312 | ||
| 5835 | 13년 전 | 1516 | ||
| 5834 | 13년 전 | 1501 | ||
| 5833 | 13년 전 | 6670 | ||
| 5832 | 13년 전 | 5210 | ||
| 5831 | 13년 전 | 1068 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기