<?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);
?>
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 5530 | 13년 전 | 551 | ||
| 5529 | 13년 전 | 738 | ||
| 5528 | 13년 전 | 727 | ||
| 5527 | 13년 전 | 1041 | ||
| 5526 | 13년 전 | 1052 | ||
| 5525 | 13년 전 | 1817 | ||
| 5524 | 13년 전 | 688 | ||
| 5523 |
high8sky
|
13년 전 | 742 | |
| 5522 | 13년 전 | 3138 | ||
| 5521 | 13년 전 | 869 | ||
| 5520 |
즐거운상상을
|
13년 전 | 1127 | |
| 5519 | 13년 전 | 1502 | ||
| 5518 | 13년 전 | 959 | ||
| 5517 | 13년 전 | 1963 | ||
| 5516 | 13년 전 | 677 | ||
| 5515 |
순천홈페이지
|
13년 전 | 2836 | |
| 5514 | 13년 전 | 1174 | ||
| 5513 |
수야3019
|
13년 전 | 1500 | |
| 5512 | 13년 전 | 904 | ||
| 5511 | 13년 전 | 1060 | ||
| 5510 |
|
13년 전 | 1419 | |
| 5509 |
|
13년 전 | 1104 | |
| 5508 | 13년 전 | 1668 | ||
| 5507 | 13년 전 | 1541 | ||
| 5506 | 13년 전 | 712 | ||
| 5505 | 13년 전 | 2790 | ||
| 5504 |
물끄덩미끄덩
|
13년 전 | 952 | |
| 5503 |
후라보노보노
|
13년 전 | 1976 | |
| 5502 | 13년 전 | 869 | ||
| 5501 | 13년 전 | 1951 | ||
| 5500 | 13년 전 | 1817 | ||
| 5499 | 13년 전 | 1814 | ||
| 5498 | 13년 전 | 768 | ||
| 5497 |
레인보우1492
|
13년 전 | 1336 | |
| 5496 | 13년 전 | 1070 | ||
| 5495 |
jdjjun00
|
13년 전 | 2047 | |
| 5494 | 13년 전 | 907 | ||
| 5493 | 13년 전 | 986 | ||
| 5492 | 13년 전 | 1235 | ||
| 5491 | 13년 전 | 1086 | ||
| 5490 | 13년 전 | 877 | ||
| 5489 |
빨간망사챠챠
|
13년 전 | 2280 | |
| 5488 |
나태한개미
|
13년 전 | 1066 | |
| 5487 |
나태한개미
|
13년 전 | 1028 | |
| 5486 |
나태한개미
|
13년 전 | 2118 | |
| 5485 | 13년 전 | 1803 | ||
| 5484 | 13년 전 | 6531 | ||
| 5483 | 13년 전 | 1430 | ||
| 5482 |
Raincommunication
|
13년 전 | 769 | |
| 5481 |
|
13년 전 | 577 | |
| 5480 |
|
13년 전 | 996 | |
| 5479 | 13년 전 | 1034 | ||
| 5478 |
|
13년 전 | 884 | |
| 5477 | 13년 전 | 669 | ||
| 5476 | 13년 전 | 1116 | ||
| 5475 | 13년 전 | 1434 | ||
| 5474 | 13년 전 | 823 | ||
| 5473 | 13년 전 | 645 | ||
| 5472 | 13년 전 | 1141 | ||
| 5471 | 13년 전 | 1604 | ||
| 5470 | 13년 전 | 950 | ||
| 5469 |
BackToHeaven
|
13년 전 | 2218 | |
| 5468 |
멀티트리플
|
13년 전 | 1100 | |
| 5467 | 13년 전 | 726 | ||
| 5466 | 13년 전 | 1302 | ||
| 5465 | 13년 전 | 1409 | ||
| 5464 | 13년 전 | 1491 | ||
| 5463 | 13년 전 | 687 | ||
| 5462 | 13년 전 | 1415 | ||
| 5461 | 13년 전 | 1047 | ||
| 5460 | 13년 전 | 2558 | ||
| 5459 | 13년 전 | 1063 | ||
| 5458 |
프로프리랜서
|
13년 전 | 953 | |
| 5457 | 13년 전 | 805 | ||
| 5456 |
PHPㅡASP프로그래머
|
13년 전 | 1324 | |
| 5455 |
뭐먹고살지ㅠ
|
13년 전 | 861 | |
| 5454 | 13년 전 | 1613 | ||
| 5453 |
프리랜서클럽
|
13년 전 | 1190 | |
| 5452 | 13년 전 | 830 | ||
| 5451 | 13년 전 | 781 | ||
| 5450 | 13년 전 | 7289 | ||
| 5449 |
PHPㅡASP프로그래머
|
13년 전 | 830 | |
| 5448 |
DBDBDB
|
13년 전 | 666 | |
| 5447 | 13년 전 | 1943 | ||
| 5446 |
헬프데스크
|
13년 전 | 1799 | |
| 5445 | 13년 전 | 961 | ||
| 5444 |
Werbershinta
|
13년 전 | 675 | |
| 5443 | 13년 전 | 1342 | ||
| 5442 | 13년 전 | 1060 | ||
| 5441 | 13년 전 | 1174 | ||
| 5440 | 13년 전 | 3166 | ||
| 5439 | 13년 전 | 831 | ||
| 5438 |
ddokkani
|
13년 전 | 764 | |
| 5437 | 13년 전 | 2627 | ||
| 5436 | 13년 전 | 1017 | ||
| 5435 |
PHPㅡASP프로그래머
|
13년 전 | 836 | |
| 5434 |
돗단배123
|
13년 전 | 1609 | |
| 5433 | 13년 전 | 1766 | ||
| 5432 |
|
13년 전 | 917 | |
| 5431 | 13년 전 | 765 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기