<?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);
?>
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 4430 | 13년 전 | 827 | ||
| 4429 | 13년 전 | 1151 | ||
| 4428 | 13년 전 | 1940 | ||
| 4427 | 13년 전 | 1059 | ||
| 4426 | 13년 전 | 521 | ||
| 4425 | 13년 전 | 9882 | ||
| 4424 |
|
13년 전 | 848 | |
| 4423 |
|
13년 전 | 728 | |
| 4422 |
aequum
|
13년 전 | 1299 | |
| 4421 | 13년 전 | 2415 | ||
| 4420 | 13년 전 | 1205 | ||
| 4419 | 13년 전 | 889 | ||
| 4418 |
한번잘해보자
|
13년 전 | 672 | |
| 4417 | 13년 전 | 1579 | ||
| 4416 | 13년 전 | 872 | ||
| 4415 | 13년 전 | 2253 | ||
| 4414 | 13년 전 | 680 | ||
| 4413 | 13년 전 | 678 | ||
| 4412 | 13년 전 | 820 | ||
| 4411 | 13년 전 | 1438 | ||
| 4410 |
|
13년 전 | 727 | |
| 4409 | 13년 전 | 2167 | ||
| 4408 |
visualp
|
13년 전 | 535 | |
| 4407 |
visualp
|
13년 전 | 3089 | |
| 4406 |
visualp
|
13년 전 | 3255 | |
| 4405 |
visualp
|
13년 전 | 3153 | |
| 4404 |
visualp
|
13년 전 | 2978 | |
| 4403 |
|
13년 전 | 671 | |
| 4402 |
gender
|
13년 전 | 626 | |
| 4401 | 13년 전 | 1119 | ||
| 4400 |
aequum
|
13년 전 | 1380 | |
| 4399 | 13년 전 | 588 | ||
| 4398 | 13년 전 | 670 | ||
| 4397 |
|
13년 전 | 583 | |
| 4396 |
aequum
|
13년 전 | 4664 | |
| 4395 |
|
13년 전 | 567 | |
| 4394 |
aequum
|
13년 전 | 4934 | |
| 4393 |
|
13년 전 | 1269 | |
| 4392 | 13년 전 | 1060 | ||
| 4391 |
mirrV
|
13년 전 | 541 | |
| 4390 |
파워웹프로
|
13년 전 | 709 | |
| 4389 | 13년 전 | 1228 | ||
| 4388 |
Coding
|
13년 전 | 707 | |
| 4387 |
aequum
|
13년 전 | 1366 | |
| 4386 | 13년 전 | 870 | ||
| 4385 | 13년 전 | 722 | ||
| 4384 | 13년 전 | 788 | ||
| 4383 | 13년 전 | 2900 | ||
| 4382 | 13년 전 | 613 | ||
| 4381 | 13년 전 | 1188 | ||
| 4380 | 13년 전 | 814 | ||
| 4379 |
|
13년 전 | 751 | |
| 4378 | 13년 전 | 664 | ||
| 4377 | 13년 전 | 3300 | ||
| 4376 |
aequum
|
13년 전 | 1217 | |
| 4375 |
클로로다인
|
13년 전 | 650 | |
| 4374 |
DDFACTORY
|
13년 전 | 719 | |
| 4373 |
까탈스런ET
|
13년 전 | 708 | |
| 4372 | 13년 전 | 810 | ||
| 4371 | 13년 전 | 572 | ||
| 4370 |
|
13년 전 | 651 | |
| 4369 |
프리프리닷
|
13년 전 | 1303 | |
| 4368 | 13년 전 | 3172 | ||
| 4367 |
soing
|
13년 전 | 1585 | |
| 4366 |
|
13년 전 | 685 | |
| 4365 |
|
13년 전 | 623 | |
| 4364 |
|
13년 전 | 760 | |
| 4363 |
|
13년 전 | 624 | |
| 4362 |
|
13년 전 | 728 | |
| 4361 |
|
13년 전 | 843 | |
| 4360 |
|
13년 전 | 650 | |
| 4359 |
|
13년 전 | 3126 | |
| 4358 |
|
13년 전 | 3041 | |
| 4357 | 13년 전 | 841 | ||
| 4356 | 13년 전 | 1342 | ||
| 4355 | 13년 전 | 968 | ||
| 4354 | 13년 전 | 815 | ||
| 4353 | 13년 전 | 3374 | ||
| 4352 | 13년 전 | 2377 | ||
| 4351 | 13년 전 | 1966 | ||
| 4350 |
|
13년 전 | 1885 | |
| 4349 | 13년 전 | 660 | ||
| 4348 |
aequum
|
13년 전 | 1422 | |
| 4347 | 13년 전 | 663 | ||
| 4346 |
|
13년 전 | 566 | |
| 4345 | 13년 전 | 598 | ||
| 4344 |
aequum
|
13년 전 | 1007 | |
| 4343 |
|
13년 전 | 1041 | |
| 4342 |
aequum
|
13년 전 | 1640 | |
| 4341 | 13년 전 | 809 | ||
| 4340 |
2번호랑이
|
13년 전 | 1009 | |
| 4339 |
|
13년 전 | 1170 | |
| 4338 | 13년 전 | 1167 | ||
| 4337 | 13년 전 | 519 | ||
| 4336 |
aequum
|
13년 전 | 1710 | |
| 4335 | 13년 전 | 891 | ||
| 4334 | 13년 전 | 1194 | ||
| 4333 |
Sturmvogel
|
13년 전 | 964 | |
| 4332 |
aequum
|
13년 전 | 1283 | |
| 4331 |
aequum
|
13년 전 | 1405 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기