<?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);
?>
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 8030 | 9년 전 | 354 | ||
| 8029 | 9년 전 | 286 | ||
| 8028 | 9년 전 | 254 | ||
| 8027 | 9년 전 | 265 | ||
| 8026 | 9년 전 | 309 | ||
| 8025 | 9년 전 | 367 | ||
| 8024 | 9년 전 | 333 | ||
| 8023 | 9년 전 | 380 | ||
| 8022 | 9년 전 | 310 | ||
| 8021 | 9년 전 | 314 | ||
| 8020 | 9년 전 | 307 | ||
| 8019 | 9년 전 | 330 | ||
| 8018 | 9년 전 | 436 | ||
| 8017 | 9년 전 | 530 | ||
| 8016 | 9년 전 | 317 | ||
| 8015 | 9년 전 | 381 | ||
| 8014 | 9년 전 | 314 | ||
| 8013 | 9년 전 | 227 | ||
| 8012 | 9년 전 | 236 | ||
| 8011 | 9년 전 | 435 | ||
| 8010 | 9년 전 | 289 | ||
| 8009 | 9년 전 | 273 | ||
| 8008 | 9년 전 | 278 | ||
| 8007 | 9년 전 | 420 | ||
| 8006 | 9년 전 | 454 | ||
| 8005 |
|
9년 전 | 956 | |
| 8004 | 9년 전 | 341 | ||
| 8003 | 9년 전 | 412 | ||
| 8002 | 9년 전 | 317 | ||
| 8001 |
|
9년 전 | 660 | |
| 8000 | 9년 전 | 404 | ||
| 7999 | 9년 전 | 365 | ||
| 7998 | 9년 전 | 418 | ||
| 7997 | 9년 전 | 304 | ||
| 7996 | 9년 전 | 529 | ||
| 7995 | 9년 전 | 444 | ||
| 7994 | 9년 전 | 291 | ||
| 7993 | 9년 전 | 364 | ||
| 7992 | 9년 전 | 499 | ||
| 7991 | 9년 전 | 240 | ||
| 7990 | 9년 전 | 261 | ||
| 7989 | 9년 전 | 293 | ||
| 7988 | 9년 전 | 718 | ||
| 7987 | 9년 전 | 412 | ||
| 7986 | 9년 전 | 401 | ||
| 7985 | 9년 전 | 501 | ||
| 7984 | 9년 전 | 421 | ||
| 7983 | 9년 전 | 642 | ||
| 7982 | 9년 전 | 504 | ||
| 7981 | 9년 전 | 451 | ||
| 7980 | 9년 전 | 479 | ||
| 7979 | 9년 전 | 452 | ||
| 7978 | 9년 전 | 433 | ||
| 7977 | 9년 전 | 373 | ||
| 7976 | 9년 전 | 844 | ||
| 7975 | 9년 전 | 353 | ||
| 7974 | 9년 전 | 384 | ||
| 7973 | 9년 전 | 584 | ||
| 7972 | 9년 전 | 370 | ||
| 7971 | 9년 전 | 445 | ||
| 7970 | 9년 전 | 285 | ||
| 7969 | 9년 전 | 532 | ||
| 7968 | 9년 전 | 370 | ||
| 7967 | 9년 전 | 358 | ||
| 7966 | 9년 전 | 361 | ||
| 7965 |
|
9년 전 | 1007 | |
| 7964 | 9년 전 | 391 | ||
| 7963 | 9년 전 | 380 | ||
| 7962 | 9년 전 | 362 | ||
| 7961 |
전갈자리남자
|
9년 전 | 499 | |
| 7960 | 9년 전 | 954 | ||
| 7959 | 9년 전 | 544 | ||
| 7958 | 9년 전 | 400 | ||
| 7957 | 9년 전 | 360 | ||
| 7956 | 9년 전 | 364 | ||
| 7955 | 9년 전 | 435 | ||
| 7954 | 9년 전 | 362 | ||
| 7953 | 9년 전 | 418 | ||
| 7952 | 9년 전 | 345 | ||
| 7951 | 9년 전 | 491 | ||
| 7950 | 9년 전 | 379 | ||
| 7949 | 9년 전 | 381 | ||
| 7948 | 9년 전 | 316 | ||
| 7947 | 9년 전 | 922 | ||
| 7946 | 9년 전 | 413 | ||
| 7945 | 9년 전 | 383 | ||
| 7944 | 9년 전 | 396 | ||
| 7943 | 9년 전 | 360 | ||
| 7942 | 9년 전 | 399 | ||
| 7941 | 9년 전 | 379 | ||
| 7940 | 9년 전 | 871 | ||
| 7939 | 9년 전 | 333 | ||
| 7938 | 9년 전 | 366 | ||
| 7937 | 9년 전 | 268 | ||
| 7936 | 9년 전 | 871 | ||
| 7935 | 9년 전 | 429 | ||
| 7934 | 9년 전 | 396 | ||
| 7933 | 9년 전 | 483 | ||
| 7932 | 9년 전 | 454 | ||
| 7931 | 9년 전 | 511 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기