<?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);
?>
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 5730 | 13년 전 | 776 | ||
| 5729 | 13년 전 | 3591 | ||
| 5728 | 13년 전 | 1162 | ||
| 5727 |
freejazzme
|
13년 전 | 1114 | |
| 5726 | 13년 전 | 1451 | ||
| 5725 |
itlang
|
13년 전 | 435 | |
| 5724 | 13년 전 | 514 | ||
| 5723 |
crocojea
|
13년 전 | 1502 | |
| 5722 | 13년 전 | 1985 | ||
| 5721 | 13년 전 | 714 | ||
| 5720 |
쿠우우우우
|
13년 전 | 472 | |
| 5719 | 13년 전 | 619 | ||
| 5718 |
|
13년 전 | 595 | |
| 5717 | 13년 전 | 1453 | ||
| 5716 |
|
13년 전 | 1043 | |
| 5715 | 13년 전 | 470 | ||
| 5714 | 13년 전 | 473 | ||
| 5713 | 13년 전 | 537 | ||
| 5712 |
|
13년 전 | 775 | |
| 5711 | 13년 전 | 697 | ||
| 5710 |
minini
|
13년 전 | 490 | |
| 5709 |
|
13년 전 | 1335 | |
| 5708 | 13년 전 | 688 | ||
| 5707 | 13년 전 | 5860 | ||
| 5706 |
오니기리죠
|
13년 전 | 1026 | |
| 5705 |
HSEngine
|
13년 전 | 659 | |
| 5704 |
Giggle
|
13년 전 | 1699 | |
| 5703 | 13년 전 | 507 | ||
| 5702 |
AMDbest
|
13년 전 | 1424 | |
| 5701 |
|
13년 전 | 2891 | |
| 5700 | 13년 전 | 505 | ||
| 5699 |
미션임파썩을
|
13년 전 | 543 | |
| 5698 | 13년 전 | 630 | ||
| 5697 | 13년 전 | 548 | ||
| 5696 | 13년 전 | 457 | ||
| 5695 |
|
13년 전 | 710 | |
| 5694 | 13년 전 | 446 | ||
| 5693 | 13년 전 | 979 | ||
| 5692 | 13년 전 | 951 | ||
| 5691 |
쉽다zzz
|
13년 전 | 718 | |
| 5690 | 13년 전 | 474 | ||
| 5689 | 13년 전 | 635 | ||
| 5688 | 13년 전 | 1416 | ||
| 5687 | 13년 전 | 467 | ||
| 5686 | 13년 전 | 2452 | ||
| 5685 |
AMDbest
|
13년 전 | 2158 | |
| 5684 | 13년 전 | 2038 | ||
| 5683 | 13년 전 | 1361 | ||
| 5682 |
AMDbest
|
13년 전 | 706 | |
| 5681 | 13년 전 | 3808 | ||
| 5680 |
|
13년 전 | 1684 | |
| 5679 | 13년 전 | 2091 | ||
| 5678 |
|
13년 전 | 532 | |
| 5677 |
mobiler
|
13년 전 | 466 | |
| 5676 | 13년 전 | 1606 | ||
| 5675 | 13년 전 | 591 | ||
| 5674 |
PHPㅡASP프로그래머
|
13년 전 | 1824 | |
| 5673 |
PHPㅡASP프로그래머
|
13년 전 | 1491 | |
| 5672 |
PHPㅡASP프로그래머
|
13년 전 | 1281 | |
| 5671 |
PHPㅡASP프로그래머
|
13년 전 | 1213 | |
| 5670 |
PHPㅡASP프로그래머
|
13년 전 | 4612 | |
| 5669 | 13년 전 | 3050 | ||
| 5668 | 13년 전 | 1413 | ||
| 5667 | 13년 전 | 494 | ||
| 5666 | 13년 전 | 1144 | ||
| 5665 |
Darby
|
13년 전 | 1610 | |
| 5664 | 13년 전 | 1341 | ||
| 5663 | 13년 전 | 1124 | ||
| 5662 | 13년 전 | 790 | ||
| 5661 | 13년 전 | 453 | ||
| 5660 | 13년 전 | 842 | ||
| 5659 | 13년 전 | 710 | ||
| 5658 | 13년 전 | 531 | ||
| 5657 | 13년 전 | 536 | ||
| 5656 | 13년 전 | 991 | ||
| 5655 | 13년 전 | 437 | ||
| 5654 | 13년 전 | 390 | ||
| 5653 |
졸린다젠장
|
13년 전 | 478 | |
| 5652 |
|
13년 전 | 398 | |
| 5651 | 13년 전 | 1028 | ||
| 5650 | 13년 전 | 722 | ||
| 5649 | 13년 전 | 2234 | ||
| 5648 | 13년 전 | 479 | ||
| 5647 | 13년 전 | 757 | ||
| 5646 | 13년 전 | 1493 | ||
| 5645 | 13년 전 | 679 | ||
| 5644 | 13년 전 | 614 | ||
| 5643 |
|
13년 전 | 573 | |
| 5642 |
쿠마하우스
|
13년 전 | 685 | |
| 5641 |
goaway
|
13년 전 | 1084 | |
| 5640 |
쿠마하우스
|
13년 전 | 647 | |
| 5639 | 13년 전 | 674 | ||
| 5638 |
쿠마하우스
|
13년 전 | 993 | |
| 5637 | 13년 전 | 823 | ||
| 5636 | 13년 전 | 1416 | ||
| 5635 |
goaway
|
13년 전 | 910 | |
| 5634 |
lllolll
|
13년 전 | 419 | |
| 5633 | 13년 전 | 966 | ||
| 5632 | 13년 전 | 4273 | ||
| 5631 | 13년 전 | 572 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기