<?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);
?>
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 630 | 19년 전 | 2363 | ||
| 629 |
|
19년 전 | 2025 | |
| 628 |
|
19년 전 | 3137 | |
| 627 |
|
19년 전 | 2041 | |
| 626 |
|
19년 전 | 2073 | |
| 625 |
|
19년 전 | 1732 | |
| 624 |
|
19년 전 | 2243 | |
| 623 | 19년 전 | 2211 | ||
| 622 |
|
19년 전 | 2519 | |
| 621 |
|
19년 전 | 2927 | |
| 620 |
|
19년 전 | 2421 | |
| 619 | 19년 전 | 2491 | ||
| 618 | 19년 전 | 3520 | ||
| 617 |
|
19년 전 | 3242 | |
| 616 |
|
19년 전 | 3233 | |
| 615 |
|
19년 전 | 3058 | |
| 614 |
|
19년 전 | 2054 | |
| 613 |
|
19년 전 | 2404 | |
| 612 |
|
19년 전 | 2249 | |
| 611 |
|
19년 전 | 2093 | |
| 610 |
|
19년 전 | 2529 | |
| 609 |
|
19년 전 | 2439 | |
| 608 |
|
19년 전 | 2827 | |
| 607 | 19년 전 | 2202 | ||
| 606 | 19년 전 | 3545 | ||
| 605 | 19년 전 | 2004 | ||
| 604 | 19년 전 | 2626 | ||
| 603 | 19년 전 | 1627 | ||
| 602 |
|
19년 전 | 2849 | |
| 601 | 19년 전 | 3081 | ||
| 600 |
|
19년 전 | 2159 | |
| 599 | 19년 전 | 2011 | ||
| 598 | 19년 전 | 2493 | ||
| 597 | 19년 전 | 2402 | ||
| 596 |
|
19년 전 | 3084 | |
| 595 |
|
19년 전 | 6771 | |
| 594 | 19년 전 | 2719 | ||
| 593 | 19년 전 | 3195 | ||
| 592 |
|
19년 전 | 3098 | |
| 591 |
|
19년 전 | 1946 | |
| 590 | 19년 전 | 3372 | ||
| 589 | 19년 전 | 2223 | ||
| 588 |
|
19년 전 | 2708 | |
| 587 | 19년 전 | 2352 | ||
| 586 |
|
19년 전 | 4373 | |
| 585 | 19년 전 | 2507 | ||
| 584 | 19년 전 | 2772 | ||
| 583 |
|
19년 전 | 3538 | |
| 582 |
|
19년 전 | 3729 | |
| 581 |
|
19년 전 | 3264 | |
| 580 | 19년 전 | 2490 | ||
| 579 | 19년 전 | 3099 | ||
| 578 | 19년 전 | 4014 | ||
| 577 | 19년 전 | 3833 | ||
| 576 | 19년 전 | 1779 | ||
| 575 |
|
19년 전 | 2233 | |
| 574 |
|
19년 전 | 5409 | |
| 573 | 19년 전 | 6745 | ||
| 572 | 19년 전 | 2584 | ||
| 571 | 19년 전 | 2119 | ||
| 570 | 19년 전 | 2606 | ||
| 569 | 19년 전 | 3322 | ||
| 568 | 19년 전 | 3548 | ||
| 567 | 19년 전 | 2989 | ||
| 566 | 19년 전 | 2610 | ||
| 565 |
|
19년 전 | 4732 | |
| 564 |
|
19년 전 | 6743 | |
| 563 |
|
19년 전 | 5017 | |
| 562 |
|
19년 전 | 5965 | |
| 561 |
|
19년 전 | 2711 | |
| 560 |
|
19년 전 | 2572 | |
| 559 |
|
19년 전 | 2237 | |
| 558 |
|
19년 전 | 2311 | |
| 557 | 19년 전 | 4599 | ||
| 556 |
|
19년 전 | 4678 | |
| 555 | 19년 전 | 2518 | ||
| 554 | 19년 전 | 2188 | ||
| 553 | 19년 전 | 2532 | ||
| 552 |
|
19년 전 | 3182 | |
| 551 | 19년 전 | 2949 | ||
| 550 |
|
19년 전 | 1907 | |
| 549 |
|
19년 전 | 1976 | |
| 548 |
|
19년 전 | 3160 | |
| 547 |
|
19년 전 | 2361 | |
| 546 |
|
19년 전 | 3634 | |
| 545 |
|
19년 전 | 2571 | |
| 544 |
|
19년 전 | 1865 | |
| 543 |
|
19년 전 | 2464 | |
| 542 |
|
19년 전 | 1738 | |
| 541 |
|
19년 전 | 1420 | |
| 540 |
|
19년 전 | 1561 | |
| 539 |
|
19년 전 | 1813 | |
| 538 |
|
19년 전 | 1600 | |
| 537 |
|
19년 전 | 1804 | |
| 536 |
|
19년 전 | 1572 | |
| 535 |
|
19년 전 | 1965 | |
| 534 |
|
19년 전 | 1854 | |
| 533 |
|
19년 전 | 1463 | |
| 532 |
|
19년 전 | 1454 | |
| 531 |
|
19년 전 | 1374 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기