画法的原理参考教科书就行,这里给出自己写的代码(可能有BUG)
包含
BHLine(BH直线)
mpline(中点直线)
DDAline(DDA直线,可能有问题,线条不太顺)
MDcircle(中点画圆)
BHcircle(BH画圆)
MDellipse(中点画椭)
除算法本身外的必要函数使用了EasyX库,在此感谢 EasyX 团队。
//#include <stdafx.h>
#include <bits/stdc++.h>
#include <graphics.h>
#include <conio.h>
using namespace std;
const int INF = 0x3f3f3f3f;
void ddaline(int stx, int sty, int enx, int eny, int color) {
if (stx > enx) swap(stx, enx), swap(sty, eny);
if (stx == enx) {
if (sty > eny) swap(sty, eny);
while (sty <= eny) {
putpixel(stx, sty, color);
sty++;
}
}
else if (sty == eny) {
while (stx <= enx) {
putpixel(stx, sty, color);
stx++;
}
}
else {
double k = (double)(eny - sty) / (enx - stx);
double y = sty;
for (; stx <= enx; stx++) {
putpixel(stx, (int)(y + 0.5), color);
y += k;
}
}
}
void mpline(int stx, int sty, int enx, int eny, int color) {
if (stx > enx) swap(stx, enx), swap(sty, eny);
int x = stx, y = sty;
if (stx == enx) {
y = min(sty, eny);
eny = max