<?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);
?>
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 6530 |
퍼블리셔강
|
12년 전 | 645 | |
| 6529 | 12년 전 | 1299 | ||
| 6528 | 12년 전 | 619 | ||
| 6527 | 12년 전 | 788 | ||
| 6526 | 12년 전 | 6577 | ||
| 6525 | 12년 전 | 548 | ||
| 6524 | 12년 전 | 836 | ||
| 6523 | 12년 전 | 482 | ||
| 6522 | 12년 전 | 531 | ||
| 6521 | 12년 전 | 797 | ||
| 6520 | 12년 전 | 737 | ||
| 6519 | 12년 전 | 1738 | ||
| 6518 |
가슴시린하늘
|
12년 전 | 1723 | |
| 6517 | 12년 전 | 1361 | ||
| 6516 | 12년 전 | 5225 | ||
| 6515 | 12년 전 | 1494 | ||
| 6514 | 12년 전 | 1596 | ||
| 6513 | 12년 전 | 950 | ||
| 6512 | 12년 전 | 1975 | ||
| 6511 | 12년 전 | 1367 | ||
| 6510 | 12년 전 | 3054 | ||
| 6509 |
프로프리랜서
|
12년 전 | 2547 | |
| 6508 |
프로프리랜서
|
12년 전 | 1897 | |
| 6507 |
프로프리랜서
|
12년 전 | 2373 | |
| 6506 |
프로프리랜서
|
12년 전 | 1852 | |
| 6505 |
프로프리랜서
|
12년 전 | 1631 | |
| 6504 | 12년 전 | 1020 | ||
| 6503 | 12년 전 | 1126 | ||
| 6502 |
프로프리랜서
|
12년 전 | 5552 | |
| 6501 |
프로프리랜서
|
12년 전 | 2598 | |
| 6500 |
프로프리랜서
|
12년 전 | 3081 | |
| 6499 |
프로프리랜서
|
12년 전 | 1749 | |
| 6498 |
프로프리랜서
|
12년 전 | 1460 | |
| 6497 | 12년 전 | 803 | ||
| 6496 |
yunkiri486
|
12년 전 | 1807 | |
| 6495 | 12년 전 | 916 | ||
| 6494 | 12년 전 | 1490 | ||
| 6493 | 12년 전 | 2759 | ||
| 6492 |
오늘도망했다
|
12년 전 | 2336 | |
| 6491 |
오늘도망했다
|
12년 전 | 1677 | |
| 6490 |
오늘도망했다
|
12년 전 | 6654 | |
| 6489 |
오늘도망했다
|
12년 전 | 2491 | |
| 6488 |
홈피119
|
12년 전 | 697 | |
| 6487 | 12년 전 | 663 | ||
| 6486 | 12년 전 | 1407 | ||
| 6485 | 12년 전 | 2049 | ||
| 6484 | 12년 전 | 896 | ||
| 6483 | 12년 전 | 707 | ||
| 6482 | 12년 전 | 1332 | ||
| 6481 | 12년 전 | 1464 | ||
| 6480 |
Header
|
12년 전 | 687 | |
| 6479 |
|
12년 전 | 1124 | |
| 6478 |
개초보제이
|
12년 전 | 1392 | |
| 6477 | 12년 전 | 784 | ||
| 6476 | 12년 전 | 1071 | ||
| 6475 | 12년 전 | 3669 | ||
| 6474 | 12년 전 | 1417 | ||
| 6473 | 12년 전 | 961 | ||
| 6472 | 12년 전 | 842 | ||
| 6471 |
AMDbest
|
12년 전 | 1202 | |
| 6470 |
jinmuk
|
12년 전 | 1443 | |
| 6469 |
jinmuk
|
12년 전 | 4242 | |
| 6468 |
jinmuk
|
12년 전 | 5569 | |
| 6467 | 12년 전 | 688 | ||
| 6466 |
jinmuk
|
12년 전 | 2263 | |
| 6465 |
jinmuk
|
12년 전 | 6728 | |
| 6464 |
jinmuk
|
12년 전 | 2403 | |
| 6463 |
jinmuk
|
12년 전 | 9320 | |
| 6462 |
희망과열정
|
12년 전 | 526 | |
| 6461 |
Header
|
12년 전 | 722 | |
| 6460 |
희망과열정
|
12년 전 | 1349 | |
| 6459 |
프리랜서개발자
|
12년 전 | 1667 | |
| 6458 | 12년 전 | 1321 | ||
| 6457 |
jinmuk
|
12년 전 | 1934 | |
| 6456 |
jinmuk
|
12년 전 | 2337 | |
| 6455 |
jinmuk
|
12년 전 | 3190 | |
| 6454 |
jinmuk
|
12년 전 | 2163 | |
| 6453 |
jinmuk
|
12년 전 | 2337 | |
| 6452 |
jinmuk
|
12년 전 | 2309 | |
| 6451 |
jinmuk
|
12년 전 | 1587 | |
| 6450 |
jinmuk
|
12년 전 | 1392 | |
| 6449 |
jinmuk
|
12년 전 | 1036 | |
| 6448 |
jinmuk
|
12년 전 | 1229 | |
| 6447 |
jinmuk
|
12년 전 | 2002 | |
| 6446 |
jinmuk
|
12년 전 | 1562 | |
| 6445 |
jinmuk
|
12년 전 | 1262 | |
| 6444 |
jinmuk
|
12년 전 | 2303 | |
| 6443 |
jinmuk
|
12년 전 | 2041 | |
| 6442 |
jinmuk
|
12년 전 | 1882 | |
| 6441 |
jinmuk
|
12년 전 | 1614 | |
| 6440 |
jinmuk
|
12년 전 | 2314 | |
| 6439 |
jinmuk
|
12년 전 | 1134 | |
| 6438 |
wndProc
|
12년 전 | 774 | |
| 6437 | 12년 전 | 392 | ||
| 6436 |
senseme
|
12년 전 | 540 | |
| 6435 | 12년 전 | 1043 | ||
| 6434 | 12년 전 | 2472 | ||
| 6433 | 12년 전 | 2479 | ||
| 6432 | 12년 전 | 1556 | ||
| 6431 |
밥먹고합시다
|
12년 전 | 1183 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기