eaxyx各种图形绘制

在这里插入图片描述



一、设置窗口背景颜色

在我们正常窗口之后窗口默认是黑色
在这里插入图片描述

setbkcolor(),cleardevice()函数

在这里我们可以调用setcolor函数来改变背景颜色,用法很简单。唯一的参数就是颜色常量。

	setbkcolor(WTHITE);

但是运行之后依然发现窗口黑色,是因为原来窗口黑色依然在,覆盖了白色。这是需要调用清屏函数

cleardevice();

注意是在setbkcolor函数之后使用不是之前!!!
正确操作之后就会成功改变颜色
在这里插入图片描述

二、图形绘制

1.图形分类

椭圆ellipse
扇形pie
矩形rectangle
线line
圆角矩形roundrect
多边形polygon
putpixel
circle

不同的形状对应的参数不同这里可以参考easyx帮助文档
https://docs.easyx.cn/zh-cn/drawing-func

2.以圆形为例

在这里插入图片描述

3.circle()函数;

  • circle(int x,int y,int r);
    圆心坐标(x,y),半径——r,

代码如下(示例):

	circle(50, 50, 50);

效果图下:
在这里插入图片描述

设置圆形线条颜色,setlinecolor

  • 设置圆形线条颜色,参数为颜色常量
    同样注意该函数写在circle();函数之前
	setlinecolor(BLUE);

效果如下:
在这里插入图片描述

设置圆形线条样式, setlinestyle();

setlinestyle(PS_SOLID,6);

在这里插入图片描述

- 这里需要声明第一个参数是边线的形状:

5种边线

PS_SOLID 是 连续实线段

  • 第二个参数是边线的像素大小
    数字越大越粗

4.fillcircle();

#include<stdio.h>
#include<graphics.h>
int main()
{
	initgraph(640, 480);
	setbkcolor(WHITE);//设置背景白色
	cleardevice();//清屏去除黑色显示白色
	setlinestyle(PS_DOT,6);//设置边线样式和大小
	setlinecolor(BLUE);//设置线的颜色
	setfillcolor(YELLOW);//设置填充圆的颜色
	fillcircle(50, 50, 50);//填充圆
	system("pause");
	closegraph();
	return 0;
}

效果如下:
在这里插入图片描述

solidcircle();

#include<stdio.h>
#include<graphics.h>
int main()
{
	initgraph(640, 480);
	setbkcolor(WHITE);//设置背景白色
	cleardevice();//清屏去除黑色显示白色
	setlinestyle(PS_DOT,6);//设置边线样式和大小
	setlinecolor(BLUE);//设置线的颜色
	setfillcolor(YELLOW);//设置填充圆的颜色
	fillcircle(50, 50, 50);//填充圆
	solidcircle(50,15050);
	system("pause");
	closegraph();
	return 0;
}

效果如下:
在这里插入图片描述


总结

以上就是图形等基本操作,具体其他的形状可以去easyx帮助文档查找具体参数并使用。
在这里插入图片描述

  • 17
    点赞
  • 36
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 5
    评论
以下是使用easyx库实现柱状图移动排序插入的示例代码: ```c++ #include <graphics.h> #include <conio.h> #include <iostream> #include <vector> #include <algorithm> using namespace std; const int n = 10; // 柱状图数量 // 柱状图结构体 struct Bar { int value; int index; }; // 比较函数,用于排序 bool cmp(const Bar& a, const Bar& b) { return a.value < b.value; } int main() { initgraph(640, 480); setbkcolor(WHITE); // 初始化柱状图数组 vector<Bar> bars(n); for (int i = 0; i < n; i++) { bars[i].value = rand() % 100; bars[i].index = i; } // 排序柱状图数组 sort(bars.begin(), bars.end(), cmp); // 绘制柱状图 const int x0 = 100, y0 = 400; const int width = 40, gap = 20; for (int i = 0; i < n; i++) { int x = x0 + i * (width + gap); int y = y0 - bars[i].value * 2; setfillcolor(BLUE); fillrectangle(x, y, x + width, y0); settextcolor(BLACK); char str[10]; sprintf_s(str, "%d", bars[i].value); outtextxy(x, y - 20, str); } // 插入新的柱状图 int newValue = rand() % 100; Bar newBar = { newValue, -1 }; for (int i = 0; i < n; i++) { if (newValue < bars[i].value) { bars.insert(bars.begin() + i, newBar); break; } } if (newBar.index == -1) bars.push_back(newBar); // 更新柱状图的索引值 for (int i = 0; i < n; i++) { bars[i].index = i; } // 绘制新的柱状图 cleardevice(); for (int i = 0; i < n; i++) { int x = x0 + i * (width + gap); int y = y0 - bars[i].value * 2; setfillcolor(BLUE); fillrectangle(x, y, x + width, y0); settextcolor(BLACK); char str[10]; sprintf_s(str, "%d", bars[i].value); outtextxy(x, y - 20, str); } _getch(); closegraph(); return 0; } ``` 该示例代码使用了结构体来存储每个柱状图的值和索引,然后通过排序函数对柱状图数组进行排序。在插入新的柱状图时,遍历已排序的柱状图数组,找到第一个比新值大的柱状图位置,然后使用 `insert` 函数插入新的柱状图。最后更新所有柱状图的索引值,并重新绘制柱状图。 运行示例代码可以看到,每次运行都会在柱状图中随机插入一个新的柱状图,并且柱状图会按照从小到大的顺序排列。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

李 天 真

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值