<?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);
?>
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 4930 | 13년 전 | 669 | ||
| 4929 | 13년 전 | 2025 | ||
| 4928 | 13년 전 | 638 | ||
| 4927 |
|
13년 전 | 795 | |
| 4926 | 13년 전 | 1118 | ||
| 4925 |
techer
|
13년 전 | 1279 | |
| 4924 |
techer
|
13년 전 | 2891 | |
| 4923 |
techer
|
13년 전 | 3111 | |
| 4922 | 13년 전 | 604 | ||
| 4921 | 13년 전 | 1104 | ||
| 4920 |
StyleRoot
|
13년 전 | 585 | |
| 4919 | 13년 전 | 1164 | ||
| 4918 |
onlymilk74
|
13년 전 | 944 | |
| 4917 |
하나데이타
|
13년 전 | 831 | |
| 4916 |
하나데이타
|
13년 전 | 1158 | |
| 4915 | 13년 전 | 435 | ||
| 4914 | 13년 전 | 1831 | ||
| 4913 | 13년 전 | 1567 | ||
| 4912 | 13년 전 | 1300 | ||
| 4911 | 13년 전 | 747 | ||
| 4910 | 13년 전 | 1221 | ||
| 4909 |
성민꼬르꼬
|
13년 전 | 1450 | |
| 4908 | 13년 전 | 1045 | ||
| 4907 | 13년 전 | 2231 | ||
| 4906 | 13년 전 | 891 | ||
| 4905 |
kinyenug1
|
13년 전 | 610 | |
| 4904 |
kinyenug1
|
13년 전 | 786 | |
| 4903 | 13년 전 | 3593 | ||
| 4902 | 13년 전 | 2468 | ||
| 4901 | 13년 전 | 1025 | ||
| 4900 | 13년 전 | 1195 | ||
| 4899 | 13년 전 | 2594 | ||
| 4898 | 13년 전 | 1590 | ||
| 4897 |
다케미카코
|
13년 전 | 756 | |
| 4896 |
안뇽하어영
|
13년 전 | 816 | |
| 4895 |
baek83
|
13년 전 | 2212 | |
| 4894 | 13년 전 | 697 | ||
| 4893 | 13년 전 | 945 | ||
| 4892 | 13년 전 | 444 | ||
| 4891 | 13년 전 | 598 | ||
| 4890 | 13년 전 | 1342 | ||
| 4889 |
Black
|
13년 전 | 2883 | |
| 4888 |
techer
|
13년 전 | 639 | |
| 4887 |
techer
|
13년 전 | 906 | |
| 4886 |
visualp
|
13년 전 | 1300 | |
| 4885 | 13년 전 | 702 | ||
| 4884 |
너는나의봄이다
|
13년 전 | 2321 | |
| 4883 | 13년 전 | 923 | ||
| 4882 | 13년 전 | 1602 | ||
| 4881 | 13년 전 | 1847 | ||
| 4880 | 13년 전 | 1655 | ||
| 4879 | 13년 전 | 966 | ||
| 4878 |
|
13년 전 | 1265 | |
| 4877 | 13년 전 | 770 | ||
| 4876 |
꿈을꾸는너구리
|
13년 전 | 633 | |
| 4875 |
성민꼬르꼬
|
13년 전 | 1291 | |
| 4874 | 13년 전 | 981 | ||
| 4873 | 13년 전 | 835 | ||
| 4872 | 13년 전 | 755 | ||
| 4871 | 13년 전 | 917 | ||
| 4870 | 13년 전 | 706 | ||
| 4869 | 13년 전 | 1226 | ||
| 4868 | 13년 전 | 934 | ||
| 4867 | 13년 전 | 629 | ||
| 4866 | 13년 전 | 1239 | ||
| 4865 | 13년 전 | 876 | ||
| 4864 |
기획자정군
|
13년 전 | 1616 | |
| 4863 |
꼬꼬아부지
|
13년 전 | 1040 | |
| 4862 | 13년 전 | 3512 | ||
| 4861 |
|
13년 전 | 1572 | |
| 4860 |
|
13년 전 | 2167 | |
| 4859 | 13년 전 | 790 | ||
| 4858 | 13년 전 | 443 | ||
| 4857 | 13년 전 | 1120 | ||
| 4856 |
크라운엠버서더
|
13년 전 | 1922 | |
| 4855 | 13년 전 | 831 | ||
| 4854 | 13년 전 | 2048 | ||
| 4853 | 13년 전 | 745 | ||
| 4852 | 13년 전 | 1092 | ||
| 4851 |
꼬꼬아부지
|
13년 전 | 1801 | |
| 4850 | 13년 전 | 1113 | ||
| 4849 |
|
13년 전 | 780 | |
| 4848 | 13년 전 | 1474 | ||
| 4847 |
|
13년 전 | 3792 | |
| 4846 | 13년 전 | 518 | ||
| 4845 | 13년 전 | 583 | ||
| 4844 | 13년 전 | 768 | ||
| 4843 | 13년 전 | 3914 | ||
| 4842 | 13년 전 | 1256 | ||
| 4841 | 13년 전 | 1428 | ||
| 4840 | 13년 전 | 1437 | ||
| 4839 | 13년 전 | 744 | ||
| 4838 | 13년 전 | 621 | ||
| 4837 | 13년 전 | 769 | ||
| 4836 |
TIAMO
|
13년 전 | 1582 | |
| 4835 | 13년 전 | 948 | ||
| 4834 | 13년 전 | 1283 | ||
| 4833 | 13년 전 | 2482 | ||
| 4832 |
|
13년 전 | 945 | |
| 4831 | 13년 전 | 1260 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기