Skip to content

Commit

Permalink
style: 去除 demo 中多余的行尾空格
Browse files Browse the repository at this point in the history
  • Loading branch information
yixy-only committed Feb 26, 2024
1 parent b27cd62 commit 4eaa275
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 89 deletions.
3 changes: 1 addition & 2 deletions demo/ege5star.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const double fullCircleRatation = PI * 2; ///< 完整圆周角度(单位:弧
const double starAngle = PI * 4 / 5; ///< 五角星角度

/**
@brief 绘制五角星
@param x 中心点 x 坐标
@param y 中心点 y 坐标
Expand All @@ -45,7 +44,7 @@ int main()
r += rotatingSpeed;
if (r > fullCircleRatation)
r -= fullCircleRatation;

cleardevice(); // 清空屏幕
setcolor(EGERGB(0xff, 0xff, 0xff)); // 设置绘制颜色
setfillcolor(EGERGB(0, 0, 0xff));
Expand Down
29 changes: 14 additions & 15 deletions demo/ege_new_drawimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,24 @@ int main()
{
/// 初始化绘图窗口
initgraph(800, 600);

// @note Step 1
// @note 绘制背景
setbkcolor(WHITE);
setfillcolor(BLUE);
for (int i = 0; i < 12; i++) {
for (int i = 0; i < 12; i++) {
// @note 画无边框填充矩形
bar(0, i * 50, 800, i * 50 + 20);
}



// @note Step 2
// @note 创建一个PIMAGE对象
PIMAGE img = newimage(200, 200);
PIMAGE img = newimage(200, 200);
// @note 将背景设为透明色
setbkcolor(EGERGBA(0, 0, 0, 0), img);
setcolor(RED, img);
setfillcolor(YELLOW, img);

// @note 绘制一个多边形(示例使用三角形)
ege_point points[4];
points[0].x = 100;
Expand All @@ -51,36 +50,36 @@ int main()
points[3].x = 100;
points[3].y = 50;
// @note 绘制填充多边形到目标图像(为NULL则绘制到屏幕)并绘制边框
ege_fillpoly(3, points, img);
ege_fillpoly(3, points, img);
ege_drawpoly(4, points, img);
// @note 将图像绘制到目标图像上(为NULL则绘制到屏幕),保留透明度信息
putimage_withalpha(NULL, img, 0, 0);

// @note Step 3
// @note 将图像的指定部分绘制到屏幕,从(200,0)点开始绘制到屏幕,到(400,300)点结束
ege_drawimage(img, 200, 0, 400, 300, 0, 0, 200, 200);

// @note Step 4
// @note 通过变换矩阵来绘制图像
ege_transform_matrix m;
ege_get_transform(&m);
ege_transform_translate(400, 450);
ege_transform_translate(400, 450);
ege_transform_rotate(45.0);
ege_transform_translate(-getwidth(img) / 2, -getheight(img) / 2);
ege_drawimage(img, 0, 0);
ege_drawimage(img, 0, 0);

// @note Step 5
// @note 还原图像
ege_set_transform(&m);
/*
@note 下面的语句可以清除矩阵:
ege_transform_reset();
*/
*/
// @note 绘制到窗口
ege_drawimage(img, 600, 400);

// @note 暂停程序,等待用户按下任意键继续
getch();
getch();
delimage(img);
closegraph();
return 0;
Expand Down
3 changes: 1 addition & 2 deletions demo/egearrow.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
/**
@file egearrow.cpp
@brief 画箭头算法演示小程序
*/
#include <graphics.h>
#include <math.h>

/**
@brief 绘制箭头
@param sx 起始点 x 坐标
@param sy 起始点 y 坐标
Expand Down
32 changes: 16 additions & 16 deletions demo/egeball.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class AniObj {
obj[i].color = HSVtoRGB( myrand( 360.0f ), 1.0f, 1.0f );
}
}

/**
* @brief Updates the positions and velocities of the ball objects based on physics laws.
*/
Expand All @@ -84,7 +84,7 @@ class AniObj {
)
Crash( obj[i], obj[j] );
}

/**
* @brief Draws the ball objects on the graphics window.
*/
Expand All @@ -95,53 +95,53 @@ class AniObj {
obj[i].r * 2, obj[i].r * 2 );
}
}

/**
* @brief Destructor for AniObj.
* Cleans up any resources associated with the AniObj object.
*/
~AniObj() {
}

private:
/**
* @brief Updates the velocities of two colliding ball objects using the physics of elastic collision.
*/
void Crash( Obj &a, Obj &b ) {
float ma = a.r * a.r, mb = b.r * b.r;

float sx = a.x - b.x;
float sy = a.y - b.y;
float s1x = sx / sqrt( sx*sx + sy*sy );
float s1y = sy / sqrt( sx*sx + sy*sy );
float t1x = -s1y;
float t1y = s1x;

float vas = a.vx * s1x + a.vy * s1y;
float vat = a.vx * t1x + a.vy * t1y;
float vbs = b.vx * s1x + b.vy * s1y;
float vbt = b.vx * t1x + b.vy * t1y;

float vasf = ( 2 * mb * vbs + vas * ( ma - mb ) ) / ( ma + mb );
float vbsf = ( 2 * ma * vas - vbs * ( ma - mb ) ) / ( ma + mb );

float nsx = vasf * s1x;
float nsy = vasf * s1y;
float ntx = vat * t1x;
float nty = vat * t1y;

a.vx = nsx + ntx;
a.vy = nsy + nty;

nsx = vbsf * s1x;
nsy = vbsf * s1y;
ntx = vbt * t1x;
nty = vbt * t1y;

b.vx = nsx + ntx;
b.vy = nsy + nty;
}

private:
Obj obj[20];
int n;
Expand All @@ -155,19 +155,19 @@ int main() {
setinitmode( INIT_ANIMATION );
initgraph( 640, 480 );
randomize(); // Initialize random seed

AniObj aniobj; // Create AniObj object
fps f;
ege_enable_aa( true );

for (

; is_run(); delay_fps( 120 ) ) {
aniobj.updateobj(); // Update object positions
cleardevice();
aniobj.drawobj(); // Draw objects
}

closegraph();
return 0;
}
4 changes: 2 additions & 2 deletions demo/egeclock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ void draw()
ege::settextjustify(ege::CENTER_TEXT, ege::CENTER_TEXT);
ege::setfont(24, 0, "Courier New");
ege::setbkmode(TRANSPARENT);

ege::ege_enable_aa(true);
ege::setfillcolor(EGEARGB(0xff, 0x40, 0x40, 0x40));
ege::setcolor(EGEARGB(0xff, 0x80, 0x00, 0xf0));
ege::ege_fillellipse(center.x - r * 1.2f, center.y - r * 1.2f,
r * 1.2f * 2.0f, r * 1.2f * 2.0f);

ege::setcolor(ege::WHITE);
for (int num = 1; num <= 12; ++num)
{
Expand Down
18 changes: 9 additions & 9 deletions demo/egegetimage.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <graphics.h>
#include <string.h>
#include <stdio.h>
#include <string.h>
#include <stdio.h>

#define MSG_LEN 200

Expand All @@ -19,7 +19,7 @@ int main()
int result;
initgraph( 640, 480 );
setbkcolor(WHITE);

// @note 读取一个PNG文件(getimage.png),并使用putimage_withalpha函数在坐标(50, 50)处以带有alpha透明度的方式显示图像
img = newimage();
result = getimage(img, "getimage.png");
Expand All @@ -28,11 +28,11 @@ int main()
outtextxy(0, 440, msg);
getch();
exit(-1);
}
}
putimage_withalpha(NULL, img, 50, 50);
putimage_withalpha(NULL, img, 50, 200, 150, 150, 0, 0, getwidth(img), getheight(img));
delimage(img);

// @note 读取一个JPG文件(getimage.jpg),并使用putimage函数在坐标(200, 50)处显示图像。
img = newimage();
result = getimage(img, "getimage.jpg");
Expand All @@ -41,10 +41,10 @@ int main()
outtextxy(0, 440, msg);
getch();
exit(-1);
}
}
putimage(200, 50, img);
delimage(img);

// @note 尝试读取一个不存在的PNG文件(getimage1.png),如果读取失败,则显示错误消息。
img = newimage();
result = getimage(img, "getimage1.png");
Expand All @@ -53,10 +53,10 @@ int main()
outtextxy(0, 440, msg);
getch();
exit(-1);
}
}
putimage(50, 50, img);
delimage(img);

getch();
closegraph();
return 0;
Expand Down
8 changes: 4 additions & 4 deletions demo/egejulia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ int JDraw(COMPLEX c, double fromx, double fromy, double tox, double toy, double
continue;
}
COMPLEX& z = st->z;

if (st->iter == 0)
{
double re = fromx + (tox - fromx) * (x / (double)g_w);
Expand Down Expand Up @@ -491,15 +491,15 @@ int main(int argc, char* argv[])
// MessageBox(NULL, TEXT("本屏幕保护程序无配置"), TEXT("JuliaSet"), MB_OK);
// return 0;
// }

//initgraph(320, 240);
initgraph(-1, -1);

randomize();
showmouse(0);
flushmouse();
while(kbhit()) getch();

//InitColor();
InitLog();
g_w = getwidth(NULL);
Expand Down
Loading

0 comments on commit 4eaa275

Please sign in to comment.