rectangle(), drawpoly()

#include < graphics.h > 
#include < stdio.h > 
int main() {
    int i;
    int points[8] = {
        320,
        0,
        0,
        240,
        640,
        240,
        320,
        0
    };
    int graphdriver = DETECT;
    int graphmode;
    initgraph( & graphdriver, &graphmode, "");
    cleardevice();
    rectangle(0, 0, getmaxx(), getmaxy());
    drawpoly(4, points);
    getch();
    cleardevice();
    drawpoly(3, points);
    getch();
    closegraph();
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个示例程序,实现了读取坐标信息、绘制矩形和不规则图形,并使用EasyX库进行可视化显示: ```cpp #include <iostream> #include <fstream> #include <vector> #include <graphics.h> using namespace std; // 矩形绘制函数 void drawRectangle(int x1, int y1, int x2, int y2) { rectangle(x1, y1, x2, y2); } // 不规则图形绘制函数 void drawIrregular(vector<int>& coords) { int n = coords.size() / 2; int* points = new int[n * 2]; for (int i = 0; i < n; i++) { points[i * 2] = coords[i * 2]; points[i * 2 + 1] = coords[i * 2 + 1]; } drawpoly(n, points); delete[] points; } int main() { // 读取文件 ifstream inFile("coords.txt"); vector<int> coords; int x, y; while (inFile >> x >> y) { coords.push_back(x); coords.push_back(y); } inFile.close(); // 初始化图形界面 initgraph(800, 600); // 绘制矩形 drawRectangle(coords[0], coords[1], coords[2], coords[3]); // 绘制不规则图形 vector<int> irregularCoords(coords.begin() + 4, coords.end()); drawIrregular(irregularCoords); // 显示图形界面 getch(); closegraph(); return 0; } ``` 其中,`coords.txt`文件的内容应该如下所示: ``` 100 100 200 100 200 200 100 200 300 300 400 200 500 300 450 400 350 400 ``` 这个示例程序中,我们首先读取文件中的所有坐标点,并将它们存储在一个`vector<int>`中。然后,我们使用EasyX库提供的`rectangle`和`drawpoly`函数来分别绘制矩形和不规则图形。 需要注意的是,我们在绘制不规则图形时,需要将坐标点从`vector`中提取出来,并将它们转换为一个数组,以便传递给`drawpoly`函数。 最后,我们使用EasyX库提供的`getch`和`closegraph`函数来显示图形界面,并等待用户按下任意键关闭图形界面。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值