graphics.h 库在使用时会显示倒置的对象,也会倒置坐标

The graphics.h library when used , shows objects inverted and also inverts the coordinates too

我尝试使用以下程序编写代码来绘制底面朝下的三角形:

#include<graphics.h>
#include<conio.h>
using namespace std;
int main()
{
    initwindow(400,400,"Triangle");
    line(100,100,200,300);
    line(200,300,300,100);
    line(100,100,300,100);

    getch();
    return 0;
}



但这给出了错误的输出^^

而当我反转坐标并创建它们的镜像时,三角形就被正确绘制了

#include<graphics.h>
#include<conio.h>
using namespace std;
int main()
{
    initwindow(400,400,"Triangle");
    line(100,300,200,100);
    line(200,100,300,300);
    line(300,300,100,300);
    getch();
    return 0;
}



我该如何修复这个错误?

您似乎正在使用支持 Borland 图形接口 (BGI) 的库。在 BGI 中,原点是屏幕的左上角,正如 S.E.C.H 推测的那样。这里有一些文档:

Each pixel is specified by its row and column position where coordinates (0, 0) corresponds to the pixel in the upper-left corner of the window and (width-1, height-1) corresponds to the pixel in the lower-right corner of the window.

http://dsearls.org/courses/C122CompSci/Graphics/GraphicsIntro.htm