Diễn đàn sinh viên công nghệ thông tin, chia sẻ, giao lưu, học hỏi. Kết nối ... Những ngôn ngữ cơ bản mà bạn cần phải nắm nếu muốn thành 1 lập trình viên ...VuaTenMien.Com
Thứ Năm, 29 tháng 8, 2013
Giải thuật sinh đường Ellipse
#include <graphics.h>
#include <conio.h>
#define ROUND(a) ((long)(a+0.5))
void plot(int xc, int yc, int x, int y, int color){
putpixel(xc+x, yc+y, color);
putpixel(xc-x, yc+y, color);
putpixel(xc+x, yc-y, color);
putpixel(xc-x, yc-y, color);
}
void Mid_ellipse(int xc, int yc, int a, int b, int color){
long x, y, fx, fy, a2, b2, p;
x = 0;
y = b;
a2 = a * a;
b2 = b * b;
fx = 0;
fy = 2 * a2 * y;
plot(xc, yc, x,y, color);
p = ROUND(b2-(a2*b)+(0.25*a));
while (fx < fy){
x++;
fx += 2*b2;
if (p<0)
p += b2*(2*x +3);
else{
y--;
p+= b2*(2*x +3) + a2*(-2*y +2);
fy -= 2*a2;
}
plot(xc, yc, x, y, color);
}
p = ROUND(b2*(x+0.5)*(x+0.5) + a2*(y-1)*(y-1) - a2*b2);
while (y>0){
y--;
fy -= 2*a2;
if (p>=0)
p+=a2*(3 - 2*y);
else{
x++;
fx += 2*b2;
p += b2*(2*x+2) + a2*(-2*y +3);
}
plot(xc, yc, x, y, color);
}
}
void main(){
int gr_drive = DETECT, gr_mode;
initgraph(&gr_drive, &gr_mode, "");
Mid_Ellipse(getmaxx() / 2, getmaxy() / 2, 150, 80, 4);
getch();
closegraph();
}
Đăng ký:
Đăng Nhận xét (Atom)
Bài đăng phổ biến
-
import java.io.*; public class Test_Ngto{ public static void main(String args[]){ InputStream is = System.in; ...
-
import java.io.*; public class ReadLine{ public static void main(String args[]){ InputStreamReader isr = new InputStreamReader...
-
1. Hãy xây dựng lớp Diem cùng với các đối tượng điểm trong mặt phẳng và các phương thức sau: - Phương thức khởi tạo - Phương...
-
<html> <head> <title>Giai phuong trinh bac 2</title> <script language="JavaScript"> function giai(fo...
-
import java.io.*; public class Test_Tng{ public static void main(String args[]){ InputStream is = System.in; ...
-
<%@ Page Language="VB" Debug="true" %> <%@ Import Namespace="System.Data" %> <%@ Import Namespa...
-
<html> <head><script LANGUAGE="JavaScript"> function a_plus_b(form) { a=eval(form.a.value) ...
-
import java.io.*; public class Gptb2{ public static void main(String args[]){ InputStreamReader isr = new InputStream...
-
<html> <head> <title>giai phuong trinh bac 1</title> <script language="JavaScript"> function giai(fo...
-
<%@ Page Language="VB" Debug="true" %> <%@ Import Namespace="System.Data" %> <%@ Import Namespa...

Không có nhận xét nào:
Đăng nhận xét