This commit is contained in:
Steven Hobs
2026-03-04 17:47:10 +08:00
commit d8ba288e1d
11 changed files with 775 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
*.exe

31
.vscode/tasks.json vendored Normal file
View File

@@ -0,0 +1,31 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe 生成活动文件",
"command": "D:\\Sdk\\cc\\mingw64-15.2-msvcrt\\bin\\g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-I${workspaceFolder}\\easyx\\include",
"-L${workspaceFolder}\\easyx\\lib64",
"-leasyx",
"-lgdi32",
"-lole32",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "编译器: D:\\Sdk\\cc\\mingw64-15.2-msvcrt\\bin\\g++.exe"
}
]
}

39
caihong.cc Normal file
View File

@@ -0,0 +1,39 @@
// 编译环境Visual C++ 6.0~2022EasyX_25.9.10
// https://easyx.cn
//
#include <graphics.h>
#include <conio.h>
int main()
{
// 创建绘图窗口
initgraph(640, 480);
// 画渐变的天空(通过亮度逐渐增加)
float H = 190; // 色相
float S = 1; // 饱和度
float L = 0.7f; // 亮度
for(int y = 0; y < 480; y++)
{
L += 0.0005f;
setlinecolor( HSLtoRGB(H, S, L) );
line(0, y, 639, y);
}
// 画彩虹(通过色相逐渐增加)
H = 0;
S = 1;
L = 0.5f;
setlinestyle(PS_SOLID, 2); // 设置线宽为 2
for(int r = 400; r > 344; r--)
{
H += 5;
setlinecolor( HSLtoRGB(H, S, L) );
circle(500, 480, r);
}
// 按任意键退出
_getch();
closegraph();
return 0;
}

368
easyx/include/easyx.h Normal file
View File

@@ -0,0 +1,368 @@
/******************************************************
* EasyX Library for C++ (Ver:25.9.10)
* https://easyx.cn
*
* EasyX.h
* Provides the latest API.
******************************************************/
#pragma once
#ifndef WINVER
#define WINVER 0x0400 // Specifies that the minimum required platform is Windows 95 and Windows NT 4.0.
#endif
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0500 // Specifies that the minimum required platform is Windows 2000
#endif
#ifndef _WIN32_WINDOWS
#define _WIN32_WINDOWS 0x0410 // Specifies that the minimum required platform is Windows 98
#endif
#ifdef UNICODE
#pragma comment(lib,"EasyXw.lib")
#else
#pragma comment(lib,"EasyXa.lib")
#endif
#ifndef __cplusplus
#error EasyX is only for C++
#endif
#include <windows.h>
#include <tchar.h>
// EasyX Window Properties
#define EX_SHOWCONSOLE 1 // Maintain the console window when creating a graphics window
#define EX_NOCLOSE 2 // Disable the close button
#define EX_NOMINIMIZE 4 // Disable the minimize button
#define EX_DBLCLKS 8 // Support double-click events
// Color constant
#define BLACK 0
#define BLUE 0xAA0000
#define GREEN 0x00AA00
#define CYAN 0xAAAA00
#define RED 0x0000AA
#define MAGENTA 0xAA00AA
#define BROWN 0x0055AA
#define LIGHTGRAY 0xAAAAAA
#define DARKGRAY 0x555555
#define LIGHTBLUE 0xFF5555
#define LIGHTGREEN 0x55FF55
#define LIGHTCYAN 0xFFFF55
#define LIGHTRED 0x5555FF
#define LIGHTMAGENTA 0xFF55FF
#define YELLOW 0x55FFFF
#define WHITE 0xFFFFFF
// Color conversion macro
#define BGR(color) ( (((color) & 0xFF) << 16) | ((color) & 0xFF00FF00) | (((color) & 0xFF0000) >> 16) )
class IMAGE;
// Line style class
class LINESTYLE
{
public:
LINESTYLE();
LINESTYLE(const LINESTYLE &style);
LINESTYLE& operator = (const LINESTYLE &style);
virtual ~LINESTYLE();
DWORD style;
DWORD thickness;
DWORD *puserstyle;
DWORD userstylecount;
};
// Fill style class
class FILLSTYLE
{
public:
FILLSTYLE();
FILLSTYLE(const FILLSTYLE &style);
FILLSTYLE& operator = (const FILLSTYLE &style);
virtual ~FILLSTYLE();
int style; // Fill style
long hatch; // Hatch pattern
IMAGE* ppattern; // Fill image
};
// Image class
class IMAGE
{
public:
int getwidth() const; // Get the width of the image
int getheight() const; // Get the height of the image
protected:
int width, height; // Width and height of the image
HBITMAP m_hBmp;
HDC m_hMemDC;
float m_data[6];
COLORREF m_LineColor; // Current line color
COLORREF m_FillColor; // Current fill color
COLORREF m_TextColor; // Current text color
COLORREF m_BkColor; // Current background color
DWORD* m_pBuffer; // Memory buffer of the image
LINESTYLE m_LineStyle; // Current line style
FILLSTYLE m_FillStyle; // Current fill style
void SetDefault(); // Set the graphics environment as default
public:
IMAGE(int _width = 0, int _height = 0);
IMAGE(const IMAGE &img);
IMAGE& operator = (const IMAGE &img);
virtual ~IMAGE();
virtual void Resize(int _width, int _height); // Resize image
};
// Graphics window related functions
HWND initgraph(int width, int height, int flag = 0); // Create graphics window
void closegraph(); // Close graphics window
// Graphics environment related functions
void cleardevice(); // Clear device
void setcliprgn(HRGN hrgn); // Set clip region
void clearcliprgn(); // Clear clip region
void getlinestyle(LINESTYLE* pstyle); // Get line style
void setlinestyle(const LINESTYLE* pstyle); // Set line style
void setlinestyle(int style, int thickness = 1, const DWORD *puserstyle = NULL, DWORD userstylecount = 0); // Set line style
void getfillstyle(FILLSTYLE* pstyle); // Get fill style
void setfillstyle(const FILLSTYLE* pstyle); // Set fill style
void setfillstyle(int style, long hatch = HS_DIAGCROSS, const IMAGE* ppattern = NULL); // Set fill style
void setfillstyle(const BYTE* ppattern8x8); // Set fill style
void setorigin(int x, int y); // Set coordinate origin
void getaspectratio(float *pxasp, float *pyasp); // Get aspect ratio
void setaspectratio(float xasp, float yasp); // Set aspect ratio
int getrop2(); // Get binary raster operation mode
void setrop2(int mode); // Set binary raster operation mode
int getpolyfillmode(); // Get polygon fill mode
void setpolyfillmode(int mode); // Set polygon fill mode
void graphdefaults(); // Reset the graphics environment as default
COLORREF getlinecolor(); // Get line color
void setlinecolor(COLORREF color); // Set line color
COLORREF gettextcolor(); // Get text color
void settextcolor(COLORREF color); // Set text color
COLORREF getfillcolor(); // Get fill color
void setfillcolor(COLORREF color); // Set fill color
COLORREF getbkcolor(); // Get background color
void setbkcolor(COLORREF color); // Set background color
int getbkmode(); // Get background mode
void setbkmode(int mode); // Set background mode
// Color model transformation related functions
COLORREF RGBtoGRAY(COLORREF rgb);
void RGBtoHSL(COLORREF rgb, float *H, float *S, float *L);
void RGBtoHSV(COLORREF rgb, float *H, float *S, float *V);
COLORREF HSLtoRGB(float H, float S, float L);
COLORREF HSVtoRGB(float H, float S, float V);
// Drawing related functions
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 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
void solidrectangle(int left, int top, int right, int bottom); // Draw a filled rectangle without a border
void clearrectangle(int left, int top, int right, int bottom); // Clear a rectangular region
void 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 roundrect (int left, int top, int right, int bottom, int ellipsewidth, int ellipseheight); // Draw a rounded rectangle without filling
void fillroundrect (int left, int top, int right, int bottom, int ellipsewidth, int ellipseheight); // Draw a filled rounded rectangle with a border
void solidroundrect(int left, int top, int right, int bottom, int ellipsewidth, int ellipseheight); // Draw a filled rounded rectangle without a border
void clearroundrect(int left, int top, int right, int bottom, int ellipsewidth, int ellipseheight); // Clear a rounded rectangular region
void arc (int left, int top, int right, int bottom, double stangle, double endangle); // Draw an arc
void pie (int left, int top, int right, int bottom, double stangle, double endangle); // Draw a sector without filling
void fillpie (int left, int top, int right, int bottom, double stangle, double endangle); // Draw a filled sector with a border
void solidpie(int left, int top, int right, int bottom, double stangle, double endangle); // Draw a filled sector without a border
void clearpie(int left, int top, int right, int bottom, double stangle, double endangle); // Clear a rounded rectangular region
void polyline (const POINT *points, int num); // Draw multiple consecutive lines
void polygon (const POINT *points, int num); // Draw a polygon without filling
void fillpolygon (const POINT *points, int num); // Draw a filled polygon with a border
void solidpolygon(const POINT *points, int num); // Draw a filled polygon without a border
void clearpolygon(const POINT *points, int num); // Clear a polygon region
void polybezier(const POINT *points, int num); // Draw three square Bezier curves
void floodfill(int x, int y, COLORREF color, int filltype = FLOODFILLBORDER); // Fill the area
// Text related functions
void outtextxy(int x, int y, LPCTSTR str); // Output a string at the specified location
void outtextxy(int x, int y, TCHAR c); // Output a char at the specified location
int textwidth(LPCTSTR str); // Get the width of a string
int textwidth(TCHAR c); // Get the width of a char
int textheight(LPCTSTR str); // Get the height of a string
int textheight(TCHAR c); // Get the height of a char
int drawtext(LPCTSTR str, RECT* pRect, UINT uFormat); // Output a string in the specified format within the specified area.
int drawtext(TCHAR c, RECT* pRect, UINT uFormat); // Output a char in the specified format within the specified area.
// Set current text style.
// nHeight: The height of the text
// nWidth: The average width of the character. If 0, the scale is adaptive.
// lpszFace: The font name
// nEscapement: The writing angle of the string, 0.1 degrees, defaults to 0.
// nOrientation: The writing angle of each character, 0.1 degrees, defaults to 0.
// nWeight: The stroke weight of the character
// bItalic: Specify whether the font is italic
// bUnderline: Specify whether the font is underlined
// bStrikeOut: Specify whether the font has a strikeout
// fbCharSet: Specifies the character set
// fbOutPrecision: Specifies the output accuracy of the text
// fbClipPrecision: Specifies the clip accuracy of the text
// fbQuality: Specifies the output quality of the text
// fbPitchAndFamily: Specifies a font family that describes a font in a general way
void settextstyle(int nHeight, int nWidth, LPCTSTR lpszFace);
void settextstyle(int nHeight, int nWidth, LPCTSTR lpszFace, int nEscapement, int nOrientation, int nWeight, bool bItalic, bool bUnderline, bool bStrikeOut);
void settextstyle(int nHeight, int nWidth, LPCTSTR lpszFace, int nEscapement, int nOrientation, int nWeight, bool bItalic, bool bUnderline, bool bStrikeOut, BYTE fbCharSet, BYTE fbOutPrecision, BYTE fbClipPrecision, BYTE fbQuality, BYTE fbPitchAndFamily);
void settextstyle(const LOGFONT *font); // Set current text style
void gettextstyle(LOGFONT *font); // Get current text style
// Image related functions
int loadimage(IMAGE *pDstImg, LPCTSTR pImgFile, int nWidth = 0, int nHeight = 0, bool bResize = false); // Load image from a file (bmp/gif/jpg/png/tif/emf/wmf/ico)
int loadimage(IMAGE *pDstImg, LPCTSTR pResType, LPCTSTR pResName, int nWidth = 0, int nHeight = 0, bool bResize = false); // Load image from resources (bmp/gif/jpg/png/tif/emf/wmf/ico)
void saveimage(LPCTSTR pImgFile, const IMAGE* pImg = NULL); // Save image to a file (bmp/gif/jpg/png/tif)
void getimage(IMAGE *pDstImg, int srcX, int srcY, int srcWidth, int srcHeight); // Get image from device
void putimage(int dstX, int dstY, const IMAGE *pSrcImg, DWORD dwRop = SRCCOPY); // Put image to device
void putimage(int dstX, int dstY, int dstWidth, int dstHeight, const IMAGE *pSrcImg, int srcX, int srcY, DWORD dwRop = SRCCOPY); // Put image to device
void rotateimage(IMAGE *dstimg, const IMAGE *srcimg, double radian, COLORREF bkcolor = BLACK, bool autosize = false, bool highquality = true); // Rotate image
void Resize(IMAGE* pImg, int width, int height); // Resize the device
DWORD* GetImageBuffer(const IMAGE* pImg = NULL); // Get the display buffer of the graphics device
IMAGE* GetWorkingImage(); // Get current graphics device
void SetWorkingImage(IMAGE* pImg = NULL); // Set current graphics device
HDC GetImageHDC(const IMAGE* pImg = NULL); // Get the graphics device handle
// Other functions
int getwidth(); // Get the width of current graphics device
int getheight(); // Get the height of current graphics device
void BeginBatchDraw(); // Begin batch drawing mode
void FlushBatchDraw(); // Refreshes the undisplayed drawing
void FlushBatchDraw(int left, int top, int right, int bottom); // Refreshes the undisplayed drawing
void EndBatchDraw(); // End batch drawing mode and refreshes the undisplayed drawing
void EndBatchDraw(int left, int top, int right, int bottom); // End batch drawing mode and refreshes the undisplayed drawing
HWND GetHWnd(); // Get the handle of the graphics window
const TCHAR* GetEasyXVer(); // Get version of EasyX library
// Get user input as a dialog box
bool InputBox(LPTSTR pString, int nMaxCount, LPCTSTR pPrompt = NULL, LPCTSTR pTitle = NULL, LPCTSTR pDefault = NULL, int width = 0, int height = 0, bool bOnlyOK = true);
// Message
//
// Category Type Description
//
// EX_MOUSE WM_MOUSEMOVE Mouse moves
// WM_MOUSEWHEEL Mouse wheel is rotated
// WM_LBUTTONDOWN Left mouse button is pressed
// WM_LBUTTONUP Left mouse button is released
// WM_LBUTTONDBLCLK Left mouse button is double-clicked
// WM_MBUTTONDOWN Middle mouse button is pressed
// WM_MBUTTONUP Middle mouse button is released
// WM_MBUTTONDBLCLK Middle mouse button is double-clicked
// WM_RBUTTONDOWN Right mouse button is pressed
// WM_RBUTTONUP Right mouse button is released
// WM_RBUTTONDBLCLK Right mouse button is double-clicked
//
// EX_KEY WM_KEYDOWN A key is pressed
// WM_KEYUP A key is released
//
// EX_CHAR WM_CHAR
//
// EX_WINDOW WM_ACTIVATE The window is activated or deactivated
// WM_MOVE The window has been moved
// WM_SIZE The size of window has changed
// Message Category
#define EX_MOUSE 1
#define EX_KEY 2
#define EX_CHAR 4
#define EX_WINDOW 8
// Message Structure
struct ExMessage
{
USHORT message; // The message identifier
union
{
// Data of the mouse message
struct
{
bool ctrl :1; // Indicates whether the CTRL key is pressed
bool shift :1; // Indicates whether the SHIFT key is pressed
bool lbutton :1; // Indicates whether the left mouse button is pressed
bool mbutton :1; // Indicates whether the middle mouse button is pressed
bool rbutton :1; // Indicates whether the right mouse button is pressed
short x; // The x-coordinate of the cursor
short y; // The y-coordinate of the cursor
short wheel; // The distance the wheel is rotated, expressed in multiples or divisions of 120
};
// Data of the key message
struct
{
BYTE vkcode; // The virtual-key code of the key
BYTE scancode; // The scan code of the key. The value depends on the OEM
bool extended :1; // Indicates whether the key is an extended key, such as a function key or a key on the numeric keypad. The value is true if the key is an extended key; otherwise, it is false.
bool prevdown :1; // Indicates whether the key is previously up or down
};
// Data of the char message
TCHAR ch;
// Data of the window message
struct
{
WPARAM wParam;
LPARAM lParam;
};
};
};
// Message Function
ExMessage getmessage(BYTE filter = -1); // Get a message until a message is available for retrieval
void getmessage(ExMessage *msg, BYTE filter = -1); // Get a message until a message is available for retrieval
bool peekmessage(ExMessage *msg, BYTE filter = -1, bool removemsg = true); // Get a message if any exist, otherwise return false
void flushmessage(BYTE filter = -1); // Flush the message buffer
void setcapture(); // Enable the ability to capture mouse messages outside of the graphics window
void releasecapture(); // Disable the ability to capture mouse messages outside of the graphics window

153
easyx/include/graphics.h Normal file
View File

@@ -0,0 +1,153 @@
/******************************************************
* EasyX Library for C++ (Ver:25.9.10)
* https://easyx.cn
*
* graphics.h
* Based on easyx.h and retaining several old APIs.
* The functions and constants declared in this file are only for compatibility and are not recommended.
******************************************************/
#pragma once
#include <easyx.h>
// Old Window Properties
#define SHOWCONSOLE 1 // Maintain the console window when creating a graphics window
#define NOCLOSE 2 // Disable the close button
#define NOMINIMIZE 4 // Disable the minimize button
#define EW_SHOWCONSOLE 1 // Maintain the console window when creating a graphics window
#define EW_NOCLOSE 2 // Disable the close button
#define EW_NOMINIMIZE 4 // Disable the minimize button
#define EW_DBLCLKS 8 // Support double-click events
// Old fill styles
#define NULL_FILL BS_NULL
#define EMPTY_FILL BS_NULL
#define SOLID_FILL BS_SOLID
// Old normal fill style
#define BDIAGONAL_FILL BS_HATCHED, HS_BDIAGONAL // Fill with ///.
#define CROSS_FILL BS_HATCHED, HS_CROSS // Fill with +++.
#define DIAGCROSS_FILL BS_HATCHED, HS_DIAGCROSS // Fill with xxx (heavy cross hatch fill).
#define DOT_FILL (BYTE*)"\x80\x00\x08\x00\x80\x00\x08\x00" // Fill with xxx.
#define FDIAGONAL_FILL BS_HATCHED, HS_FDIAGONAL // Fill with \\\.
#define HORIZONTAL_FILL BS_HATCHED, HS_HORIZONTAL // Fill with ===.
#define VERTICAL_FILL BS_HATCHED, HS_VERTICAL // Fill with |||.
// Old dense fill style
#define BDIAGONAL2_FILL (BYTE*)"\x44\x88\x11\x22\x44\x88\x11\x22"
#define CROSS2_FILL (BYTE*)"\xff\x11\x11\x11\xff\x11\x11\x11"
#define DIAGCROSS2_FILL (BYTE*)"\x55\x88\x55\x22\x55\x88\x55\x22"
#define DOT2_FILL (BYTE*)"\x88\x00\x22\x00\x88\x00\x22\x00"
#define FDIAGONAL2_FILL (BYTE*)"\x22\x11\x88\x44\x22\x11\x88\x44"
#define HORIZONTAL2_FILL (BYTE*)"\x00\x00\xff\x00\x00\x00\xff\x00"
#define VERTICAL2_FILL (BYTE*)"\x11\x11\x11\x11\x11\x11\x11\x11"
// Old heavy line fill style
#define BDIAGONAL3_FILL (BYTE*)"\xe0\xc1\x83\x07\x0e\x1c\x38\x70"
#define CROSS3_FILL (BYTE*)"\x30\x30\x30\x30\x30\x30\xff\xff"
#define DIAGCROSS3_FILL (BYTE*)"\xc7\x83\xc7\xee\x7c\x38\x7c\xee"
#define DOT3_FILL (BYTE*)"\xc0\xc0\x0c\x0c\xc0\xc0\x0c\x0c"
#define FDIAGONAL3_FILL (BYTE*)"\x07\x83\xc1\xe0\x70\x38\x1c\x0e"
#define HORIZONTAL3_FILL (BYTE*)"\xff\xff\x00\x00\xff\xff\x00\x00"
#define VERTICAL3_FILL (BYTE*)"\x33\x33\x33\x33\x33\x33\x33\x33"
// Old other fill style
#define INTERLEAVE_FILL (BYTE*)"\xcc\x33\xcc\x33\xcc\x33\xcc\x33"
//
#if _MSC_VER > 1200 && _MSC_VER < 1900
#define _EASYX_DEPRECATE __declspec(deprecated("This function is deprecated."))
#define _EASYX_DEPRECATE_WITHNEW(_NewFunc) __declspec(deprecated("This function is deprecated. Instead, use this new function: " #_NewFunc ". See https://docs.easyx.cn/" #_NewFunc " for details."))
#define _EASYX_DEPRECATE_OVERLOAD(_Func) __declspec(deprecated("This overload is deprecated. See https://docs.easyx.cn/" #_Func " for details."))
#else
#define _EASYX_DEPRECATE
#define _EASYX_DEPRECATE_WITHNEW(_NewFunc)
#define _EASYX_DEPRECATE_OVERLOAD(_Func)
#endif
// Old text related functions
// nHeight: The height of the text
// nWidth: The average width of the character. If 0, the scale is adaptive.
// lpszFace: The font name
// nEscapement: The writing angle of the string, 0.1 degrees, defaults to 0.
// nOrientation: The writing angle of each character, 0.1 degrees, defaults to 0.
// nWeight: The stroke weight of the character
// bItalic: Specify whether the font is italic
// bUnderline: Specify whether the font is underlined
// bStrikeOut: Specify whether the font has a strikeout
// fbCharSet: Specifies the character set
// fbOutPrecision: Specifies the output accuracy of the text
// fbClipPrecision: Specifies the clip accuracy of the text
// fbQuality: Specifies the output quality of the text
// fbPitchAndFamily: Specifies a font family that describes a font in a general way
_EASYX_DEPRECATE_WITHNEW(settextstyle) void setfont(int nHeight, int nWidth, LPCTSTR lpszFace);
_EASYX_DEPRECATE_WITHNEW(settextstyle) void setfont(int nHeight, int nWidth, LPCTSTR lpszFace, int nEscapement, int nOrientation, int nWeight, bool bItalic, bool bUnderline, bool bStrikeOut);
_EASYX_DEPRECATE_WITHNEW(settextstyle) void setfont(int nHeight, int nWidth, LPCTSTR lpszFace, int nEscapement, int nOrientation, int nWeight, bool bItalic, bool bUnderline, bool bStrikeOut, BYTE fbCharSet, BYTE fbOutPrecision, BYTE fbClipPrecision, BYTE fbQuality, BYTE fbPitchAndFamily);
_EASYX_DEPRECATE_WITHNEW(settextstyle) void setfont(const LOGFONT *font); // Set current text style
_EASYX_DEPRECATE_WITHNEW(gettextstyle) void getfont(LOGFONT *font); // Get current text style
// Old drawing related functions
void bar(int left, int top, int right, int bottom); // Draw a filled rectangle without a border
void bar3d(int left, int top, int right, int bottom, int depth, bool topflag); // Draw a filled 3D rectangle with a border
void drawpoly(int numpoints, const int *polypoints); // Draw a polygon without filling
void fillpoly(int numpoints, const int *polypoints); // Draw a filled polygon with a border
int getmaxx(); // Get the maximum x-coordinate in the physical coordinates of the graphics window
int getmaxy(); // Get the maximum y-coordinate in the physical coordinates of the graphics window
COLORREF getcolor(); // Get current foreground color
void setcolor(COLORREF color); // Set current foreground color
void setwritemode(int mode); // Set binary raster operation mode
// Old current location related functions
_EASYX_DEPRECATE int getx(); // Get current x coordinates
_EASYX_DEPRECATE int gety(); // Get current y coordinates
_EASYX_DEPRECATE void moveto(int x, int y); // Move current location
_EASYX_DEPRECATE void moverel(int dx, int dy); // Move current location
_EASYX_DEPRECATE void lineto(int x, int y); // Draw a line
_EASYX_DEPRECATE void linerel(int dx, int dy); // Draw a line
_EASYX_DEPRECATE void outtext(LPCTSTR str); // Output a string at current location
_EASYX_DEPRECATE void outtext(TCHAR c); // Output a char at current location
// Old mouse related functions
// Mouse message
// WM_MOUSEMOVE Mouse moves
// WM_MOUSEWHEEL Mouse wheel is rotated
// WM_LBUTTONDOWN Left mouse button is pressed
// WM_LBUTTONUP Left mouse button is released
// WM_LBUTTONDBLCLK Left mouse button is double-clicked
// WM_MBUTTONDOWN Middle mouse button is pressed
// WM_MBUTTONUP Middle mouse button is released
// WM_MBUTTONDBLCLK Middle mouse button is double-clicked
// WM_RBUTTONDOWN Right mouse button is pressed
// WM_RBUTTONUP Right mouse button is released
// WM_RBUTTONDBLCLK Right mouse button is double-clicked
struct MOUSEMSG
{
UINT uMsg; // Mouse message
bool mkCtrl :1; // Indicates whether the CTRL key is pressed
bool mkShift :1; // Indicates whether the SHIFT key is pressed
bool mkLButton :1; // Indicates whether the left mouse button is pressed
bool mkMButton :1; // Indicates whether the middle mouse button is pressed
bool mkRButton :1; // Indicates whether the right mouse button is pressed
short x; // The x-coordinate of the cursor
short y; // The y-coordinate of the cursor
short wheel; // The distance the wheel is rotated, expressed in multiples or divisions of 120
};
_EASYX_DEPRECATE bool MouseHit(); // Indicates whether there are mouse messages
_EASYX_DEPRECATE_WITHNEW(getmessage) MOUSEMSG GetMouseMsg(); // Get a mouse message. if mouse message queue is empty, wait.
_EASYX_DEPRECATE_WITHNEW(peekmessage) bool PeekMouseMsg(MOUSEMSG *pMsg, bool bRemoveMsg = true); // Get a mouse message and return immediately
_EASYX_DEPRECATE_WITHNEW(flushmessage) void FlushMouseMsgBuffer(); // Empty the mouse message buffer
typedef ExMessage EASYXMSG; // Old message structure
// Old message category
#define EM_MOUSE 1
#define EM_KEY 2
#define EM_CHAR 4
#define EM_WINDOW 8

BIN
easyx/lib64/libeasyx.a Normal file

Binary file not shown.

BIN
easyx/lib64/libeasyxw.a Normal file

Binary file not shown.

25
easyx/readme.txt Normal file
View File

@@ -0,0 +1,25 @@
EasyX for MinGW
https://go.easyx.cn/easyx-for-mingw
------------------------------------
[支持 MinGW 的版本]
TDM-GCC 4.8.1 及以上版本,支持 32 位和 64 位。
MinGW-w64 的支持有限,支持 x86_64-posix-seh、x86_64-win32-seh、i686-posix-sjlj、i686-win32-sjlj但不支持 x86_64-posix-sjlj、x86_64-win32-sjlj、i686-posix-dwarf、i686-win32-dwarf。
[支持编译器的版本]
使用 TDM-GCC 4.8.1 及以上版本的集成开发环境都可以支持。例如:
● Code::Blocks 13.12 及以上版本
● DevCpp 5.8.0 及以上版本
同时额外支持:
● DevCpp 5.4.0 GCC MinGW 4.7.2
● C-Free 5.0(内置 GCC MinGW 3.4.5
[文件列表]
include 头文件
lib32 32 位库文件
lib64 64 位库文件
lib-for-devcpp_5.4.0 仅适用于 DevCpp 5.4.0 MinGW 4.7.2 和 C-Free 5.0
[安装方法]
将 include 文件夹下的头文件和 lib32/lib64 文件夹下的库文件,分别拷贝到 MinGW 的头文件和库文件文件夹中,链接选项增加:-leasyx然后编译即可。
详细步骤请参考https://go.easyx.cn/easyx-for-mingw

44
shubiao.cc Normal file
View File

@@ -0,0 +1,44 @@
// 编译环境Visual C++ 6.0~2022EasyX_25.9.10
// https://easyx.cn
//
#include <graphics.h>
int main()
{
// 初始化图形窗口
initgraph(640, 480);
ExMessage m; // 定义消息变量
while(true)
{
// 获取一条鼠标或按键消息
m = getmessage(EX_MOUSE | EX_KEY);
switch(m.message)
{
case WM_MOUSEMOVE:
// 鼠标移动的时候画红色的小点
putpixel(m.x, m.y, RED);
break;
case WM_LBUTTONDOWN:
// 如果点左键的同时按下了 Ctrl 键
if (m.ctrl)
// 画一个大方块
rectangle(m.x - 10, m.y - 10, m.x + 10, m.y + 10);
else
// 画一个小方块
rectangle(m.x - 5, m.y - 5, m.x + 5, m.y + 5);
break;
case WM_KEYDOWN:
if (m.vkcode == VK_ESCAPE)
return 0; // 按 ESC 键退出程序
}
}
// 关闭图形窗口
closegraph();
return 0;
}

67
xingkong/xingkong.cc Normal file
View File

@@ -0,0 +1,67 @@
// 编译环境Visual C++ 6.0~2022EasyX_25.9.10
// https://easyx.cn
//
#include <graphics.h>
#include <time.h>
#include <conio.h>
#define MAXSTAR 200 // 星星总数
struct STAR
{
double x;
int y;
double step;
int color;
};
STAR star[MAXSTAR];
// 初始化星星
void InitStar(int i)
{
star[i].x = 0;
star[i].y = rand() % 480;
star[i].step = (rand() % 5000) / 1000.0 + 1;
star[i].color = (int)(star[i].step * 255 / 6.0 + 0.5); // 速度越快,颜色越亮
star[i].color = RGB(star[i].color, star[i].color, star[i].color);
}
// 移动星星
void MoveStar(int i)
{
// 擦掉原来的星星
putpixel((int)star[i].x, star[i].y, 0);
// 计算新位置
star[i].x += star[i].step;
if (star[i].x > 640) InitStar(i);
// 画新星星
putpixel((int)star[i].x, star[i].y, star[i].color);
}
// 主函数
int main()
{
srand((unsigned)time(NULL)); // 随机种子
initgraph(640, 480); // 创建绘图窗口
// 初始化所有星星
for(int i = 0; i < MAXSTAR; i++)
{
InitStar(i);
star[i].x = rand() % 640;
}
// 绘制星空,按任意键退出
while(!_kbhit())
{
for(int i = 0; i < MAXSTAR; i++)
MoveStar(i);
Sleep(20);
}
closegraph(); // 关闭绘图窗口
return 0;
}

47
zifuzhen.cpp Normal file
View File

@@ -0,0 +1,47 @@
// 编译环境Visual C++ 6.0~2022EasyX_25.9.10
// https://easyx.cn
//
#include <graphics.h>
#include <time.h>
#include <conio.h>
int main()
{
// 设置随机种子
srand((unsigned) time(NULL));
// 初始化图形模式
initgraph(640, 480);
int x, y;
char c;
settextstyle(16, 8, _T("Courier")); // 设置字体
// 设置颜色
settextcolor(GREEN);
setlinecolor(BLACK);
for (int i = 0; i <= 479; i++)
{
// 在随机位置显示三个随机字母
for (int j = 0; j < 3; j++)
{
x = (rand() % 80) * 8;
y = (rand() % 20) * 24;
c = (rand() % 26) + 65;
outtextxy(x, y, c);
}
// 画线擦掉一个像素行
line(0, i, 639, i);
Sleep(10); // 延时
if (i >= 479) i = -1;
if (_kbhit()) break; // 按任意键退出
}
// 关闭图形模式
closegraph();
return 0;
}