easyx基本函数
line(x1,y1,x2,y2)
画一条(x1,y1)的点到(x2,y2)的点的直线
circle(x,y,r)
画一个圆,圆心是x,y 半径是r
putpixel(x,y,c)
画一个点x,y 像素颜色是c
solidrectangle(x1,y1,x2,y2)
画一个填充矩形,左上角是x1,y1 右上角是x2,y2
setlinecolo?
设置线条颜色为c
setbkline?
设置背景颜色为c
setfillline?
设置填充颜色为c
setcolor?
设置前景颜色为c
自定义颜色 比如RGB(x,y,c)
x代表红色,y代表绿色,c代表蓝色 可以在范围0—255之间自己定义
cleardevice()
在图形模式下清除屏幕,并且将位置移到(0,0),同时根据当前的背景颜色填充屏幕
绘图函数
作用:可以使画面运行的更加流畅
BeginBatchDraw(),FlushBatch Drew(),EndBatchDrew()
BeginBatchDraw()用于批量绘图,但是暂时不输出到屏幕上,而FlushBatchDrew()用于批量绘图,而EndBatchDrew()结束绘图,并且完成剩下的绘图,只有flush和end出现时,才能时绘图出现
setlinestyle(PS_SOLID,2) 设置实线,宽度为2的像素
GetLocalTime(&ti);//获取当前时间
outtextxy(x,y,c)是一种计算机用语,用于在指定位置显示一字符串,c是字符串
可以实现以下动画,比如制作一个多球反弹动画
#include <graphics.h>
#include <conio.h>
#include <math.h>
#define high 480
#define width 640
#define BallNume 6
float ball_x[BallNume], ball_y[BallNume];
float ball_vx[BallNume], ball_vy[BallNume];
float r;
int main()
{
initgraph(width, high);
int i, j;
r = 20;
for (i = 0; i < BallNume; i++)
{
ball_x[i] = rand() % int(width - 4 * r) + 2 * r;
ball_y[i] = rand() % int(high - 4 * r) + 2 * r;
ball_vx[i] = (rand()%2)*2-1;
ball_vy[i] = (rand()%2)*2-1;
}
BeginBatchDraw();
while (1) {
setcolor(BLACK);
setfillcolor(BLACK);
for (i = 0; i < BallNume; i++) {
fillcircle(ball_x[i], ball_y[i], r);
}
for (i = 0; i < BallNume; i++) {
ball_x[i] = ball_x[i] + ball_vx[i];
ball_y[i] = ball_y[i] + ball_vy[i];
if (ball_x[i] < r) ball_x[i] = r;
if (ball_x[i] > width - r) ball_x[i] = width - r;
if (ball_y[i] < r) ball_y[i] = r;
if (ball_y[i] > high - r) ball_y[i] = high - r;
}
for (i = 0; i < BallNume; i++) {
if ((ball_x[i] <= r) || (ball_x[i] >= width - r))
ball_vx[i] = -ball_vx[i];
else if ((ball_y[i] <= r) || (ball_y[i] >= high - r))
ball_vy[i] = -ball_vy[i];
}
float minDistances[BallNume][2];
for (i = 0; i < BallNume; i++) {
minDistances[i][0] = 999999;
minDistances[i][1] = -1;
}
for (i = 0; i < BallNume; i++) {
for (j = 0; j < BallNume; j++) {
if (i != j) {
float dist;
dist = (ball_x[i] - ball_x[j])*(ball_x[i] - ball_x[j]) + (ball_y[i] - ball_y[j])*(ball_y[i] - ball_y[j]);
if (dist < minDistances[i][0]) {
minDistances[i][0] = dist;
minDistances[i][1] = j;
}
}
}
}
for (i = 0; i < BallNume; i++) {
if (minDistances[i][0] <(4 * r * r)) {
j = minDistances[i][1];
int temp;
temp = ball_vx[i];
ball_vx[i] = ball_vx[j];
ball_vx[j] = temp;
temp = ball_vy[i];
ball_vy[i] = ball_vy[j];
ball_vy[j] = temp;
minDistances[j][0] = 999999;
minDistances[j][1] = -1;
}
}
setcolor(YELLOW);
setfillcolor(GREEN);
for (i = 0; i < BallNume; i++) {
fillcircle(ball_x[i], ball_y[i], r);
}
FlushBatchDraw();
Sleep(1);
}
EndBatchDraw();
_getch();
closegraph();
return 0;
}
其中就用到了BeginBatchDraw(),FlushBatch Drew(),EndBatchDrew()三个函数
|