左上角是坐标原点
注意标题栏不计入坐标中
getwidth()获取窗口宽度 getheight()获取窗口高度
画点头文件
COLORREF getpixel(int x, int y); // Get pixel color
void putpixel(int x, int y, COLORREF color); // Set pixel color
画线头文件
线的坐标
void line(int x1, int y1, int x2, int y2); // Draw a line
线的颜色
void setlinecolor(COLORREF color); // Set line color
线的样式
/* Pen Styles */
#define PS_SOLID 0
#define PS_DASH 1 /* ------- */
#define PS_DOT 2 /* ....... */
#define PS_DASHDOT 3 /* _._._._ */
#define PS_DASHDOTDOT 4 /* _.._.._ */
#define PS_NULL 5
#define PS_INSIDEFRAME 6
#define PS_USERSTYLE 7
#define PS_ALTERNATE 8
#define PS_STYLE_MASK 0x0000000F
画正矩形头文件
无填充
void rectangle (int left, int top, int right, int bottom); // Draw a rectangle without filling
有填充
void fillrectangle (int left, int top, int right, int bottom); // Draw a filled rectangle with a border
画圆角矩形头文件
无填充
roundrect (int left, int top, int right, int bottom, int ellipsewidth, int ellipseheight); // Draw a rounded rectangle without filling
画圆头文件
circle (int x, int y, int radius); // Draw a circle without filling
void fillcircle (int x, int y, int radius); // Draw a filled circle with a border
void solidcircle(int x, int y, int radius); // Draw a filled circle without a border
void clearcircle(int x, int y, int radius); // Clear a circular region
画椭圆头文件
void ellipse (int left, int top, int right, int bottom); // Draw an ellipse without filling
void fillellipse (int left, int top, int right, int bottom); // Draw a filled ellipse with a border
void solidellipse(int left, int top, int right, int bottom); // Draw a filled ellipse without a border
void clearellipse(int left, int top, int right, int bottom); // Clear an elliptical region
画折线头文件
void polyline (const POINT *points, int num); // Draw multiple consecutive lines
代码实现
#include <stdio.h>
#include <easyx.h>
void drawShape()
{
putpixel(50,50,RED);//绘制一个点(X,Y,颜色)
setlinecolor(BLUE);//设置线的颜色,写在前面
setlinestyle(PS_SOLID,3);//设置样式,SOLID实心,3(3个像素)影响line和rectangle
line(0, 0, 640, 480);//画线(写在后面)(起始点横坐标,起始点纵坐标,终止点横坐标,终止点纵坐标)类比向量
//画正矩形****************************************************************************************************************
rectangle(100,0,80,50);//用两个点画无填充有框正矩形(起始点横坐标,起始点纵坐标,终止点横坐标,终止点纵坐标)
setfillcolor(YELLOW);//一定要在绘制之前设置填充颜色
fillrectangle(500, 200, 400, 90);//用两个点画填充正矩形
solidrectangle(200, 500, 90, 400);//填充无边框正矩形
//*************************************************************************************************************************
//画圆角矩形**************************************************************************************************************
setfillcolor(RED);
roundrect(30,100,100,260,20,70);//前四个是矩形坐标,后两个分别是“圆”的宽度和高度(可为圆或椭圆)(长轴 短轴)))
fillroundrect(30 + 200, 100, 100 + 200, 260, 20, 70);//填充有边框圆角矩形
solidroundrect(30+500, 100, 100+500, 260, 20, 70);//填充无边框圆角矩形
//*************************************************************************************************************************
circle(50,50,20);//圆心坐标,半径
ellipse(120, 409, 21, 49);//画椭圆
POINT points[] = { {0,0},{20,20},{10,60} };//数组存储折线的”折点“
polyline(points,3);//调用数组的3个”折点“
}
int main()
{
initgraph(640,480,EX_SHOWCONSOLE);
setbkcolor(RGB(57, 155,143));//设置背景颜色
cleardevice();//填充颜色
drawShape();//一定要写,否则无法绘制图形
getchar();
return 0;
}
效果
EasyX 文档 - 图形绘制相关函数https://docs.easyx.cn/zh-cn/drawing-func
标签:PS,Draw,G3,int,void,EasyX,C语言,矩形,define From: https://blog.csdn.net/2401_85828611/article/details/140236865