EasyX库简单中文手册


 

 

EasyX库简单中文手册

作者:

时间: 2021/2/2

第一个例程

#include <graphics.h>            // 图像相关库

#include <conio.h>          // 按键获取相关库

int main()

{

       initgraph(640, 480);  // 创建一个图像画板

       circle(200, 200, 100); // 以(200,200)为圆心画一个r100的圆

       _getch();                            // 获取一个按键值

       closegraph();                     // 关闭画板

       return 0;

}

 

 


//conioConsole Input / Output(控制台输入输出)的简写,其中定义了通过控制台进行数据输入和数据输出的函数,主要是一些用户通过按键盘产生的对应操作,比如getch()函数等等。

 

 

 

基本元素——颜色

Setlinecolor,有四种格式

setlinecolor(0xff0000);

setlinecolor(BLUE);

setlinecolor(RGB(0, 0, 255));

setlinecolor(HSLtoRGB(240, 1, 0.5));

 

 

Constant

Value

Color description

BLACK

0

Black

BLUE

0xAA0000

Blue

GREEN

0x00AA00

Green

CYAN

0xAAAA00

Cyan

RED

0x0000AA

Red

MAGENTA

0xAA00AA

Magenta

BROWN

0x0055AA

Brown

LIGHTGRAY

0xAAAAAA

Light Gray

DARKGRAY

0x555555

Dark Gray

LIGHTBLUE

0xFF5555

Bright Blue

LIGHTGREEN

0x55FF55

Bright Green

LIGHTCYAN

0xFFFF55

Bright Cyan

LIGHTRED

0x5555FF

Bright Red

LIGHTMAGENTA

0xFF55FF

Bright Magenta

YELLOW

0x55FFFF

Yellow

WHITE

0xFFFFFF

White

 

基本元素——圆

void circle(int x, int y, int radius);

void fillcircle(int x, int y, int radius);

setfillcolor(BLUE);

 

无边界实现圆

void solidcircle(

    int x,

    int y,

    int radius

);

 

基本元素——直线

void line(

       int x1,

       int y1,

       int x2,

       int y2

);

 

 

基本元素——长方形

void rectangle(

       int left,

       int top,

       int right,

       int bottom

);

 

Solidrectangle  无边框填充长方形

Fillrectangle  填充长方形

基本元素——文字

       setbkmode(TRANSPARENT); // 文字除了字体外透明 

       settextstyle(40, 0, L"Verdana");   //设置字体高,宽(0自适应),字体

       wchar_t s[] = L"游戏开始";

       outtextxy(10, 20, s);

 

 

图片显示

// 从图片文件获取图像(bmp/jpg/gif/emf/wmf/ico)

void loadimage(

       IMAGE* pDstImg,            // 保存图像的 IMAGE 对象指针

       LPCTSTR pImgFile,         // 图片文件名

       int nWidth = 0,           // 图片的拉伸宽度

       int nHeight = 0,         // 图片的拉伸高度

       bool bResize = false   // 是否调整 IMAGE 的大小以适应图片

);

 

 

pDstImg:保存图像的 IMAGE 对象指针。如果为 NULL,表示图片将读取至绘图窗口。

pImgFile:图片文件名。支持 bmp / jpg / gif / emf / wmf / ico 类型的图片。gif 类型的图片仅加载第一帧,不支持透明。

nWidth:图片的拉伸宽度。加载图片后,会拉伸至该宽度。如果为 0,表示使用原图的宽度。

nHeight:图片的拉伸高度。加载图片后,会拉伸至该高度。如果为 0,表示使用原图的高度。

bResize:是否调整 IMAGE 的大小以适应图片。

 

#

include <iostream>

#include <graphics.h>      // 引用图形库头文件

#include <conio.h>

 

int main()

{

       initgraph(640, 480);   // 创建绘图窗口,大小为 640x480 像素

       IMAGE img;                 //创建IMAGE对象

       loadimage(&img, L"01.png");//绝对地址载入图片

 

       putimage(100, 0, &img);

       _getch();              // 按任意键继续

       closegraph();          // 关闭绘图窗口

}

 

鼠标的使用

struct MOUSEMSG

{

       UINT uMsg;                // Current mouse message.

       bool mkCtrl;         // The CTRL key is down.

       bool mkShift;       // The SHIFT key is down.

       bool mkLButton;         // The left mouse button is down.

       bool mkMButton;        // The middle mouse button is down.

       bool mkRButton;         // The right mouse button is down.

       int x;                           // The x-coordinate of the cursor. (physical coordinates)

       int y;                           // The y-coordinate of the cursor. (physical coordinates)

       int wheel;                    // The mouse wheel scroll value.};

 

Value

Description

WM_MOUSEMOVE

The message of the mouse movement.

WM_MOUSEWHEEL

The message of the mouse wheel scroll.

WM_LBUTTONDOWN

The message of the left mouse button down.

WM_LBUTTONUP

The message of the left mouse button up.

WM_LBUTTONDBLCLK

The message of the left mouse button double click.

WM_MBUTTONDOWN

The message of the middle mouse button down.

WM_MBUTTONUP

The message of the middle mouse button up.

WM_MBUTTONDBLCLK

The message of the middle mouse button double click.

WM_RBUTTONDOWN

The message of the right mouse button down.

WM_RBUTTONUP

The message of the right mouse button up.

WM_RBUTTONDBLCLK

The message of the right mouse button double click.

 

 

 

#include<graphics.h>

#include<conio.h>

#include<stdio.h>

 

//鼠标左键点击

int main()

{

       initgraph(800, 600);

       setbkcolor(WHITE);

       cleardevice();

 

       while (1)

       {

              MOUSEMSG m;

              if (MouseHit())

              {

                     m = GetMouseMsg();

                     if (m.uMsg == WM_LBUTTONDOWN)

                     {

                            setfillcolor(GREEN);

                            fillcircle(m.x, m.y, 30);

 

                     }

 

              }

 

       }

       return 0;

}

 

//

//// 鼠标移动

//int main()

//{

//     initgraph(800, 600);

//     setbkcolor(WHITE);

//     cleardevice();

//

//     while (1)

//     {

//            MOUSEMSG m;

//            if (MouseHit())

//            {

//                   m = GetMouseMsg();

//                   if (m.uMsg == WM_MOUSEMOVE)

//                   {

//                          setfillcolor(GREEN);

//                          fillcircle(m.x, m.y, 3);

//

//                   }

//

//            }

//

//     }

//     return 0;

//}

 

 

 

 

音乐播放

#include <windows.h>

#include <mmsystem.h>

#include<conio.h>

#pragma comment(lib, "winmm.lib")

 

int main()

{

 

       //mci: media control interface(多媒体控制接口)

       mciSendStringW(L"play 01.mp3", 0, 0, 0);

       mciSendString(L"play 01.mp3", 0, 0, 0);

       _getch();

       mciSendString(L"pause 01.mp3", 0, 0, 0);

       _getch();

       mciSendString(L"resume 01.mp3", 0, 0, 0);

 

 

       system("pause");

       return 0;

}

 

 

//open    打开设备

//close    关闭设备

//play    开始设备播放

//stop    停止设备的播放或记录

//record   开始记录

//save    保存设备内容

//pause    暂停设备的播放或记录

//resume   恢复暂停播放或记录的设备

//seek    改变媒体的当前位置

//capacility 查询设备能力

//info    查询设备的信息

//status   查询设备状态信息

 

 

批量绘图

BeginBatchDraw   这个函数用于开始批量绘图。执行后,任何绘图操作都将暂时不输出到屏幕上,直到执行   FlushBatchDraw   或    EndBatchDraw   才将之前的绘图输出。

 

随机数

rand()    参数随机数,但是每次都是一个相同序列

srand(time(0));       time(0)一般只用于重新运行时要产生不同随机数的情况,否则在这一秒内产生的随机数将会是一样的。

 

 

按键

_getchar();

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM