From 4eaa27551ec68d5e76452eaa13ca76f0488cbe43 Mon Sep 17 00:00:00 2001 From: yixy-only Date: Mon, 26 Feb 2024 19:38:08 +0800 Subject: [PATCH] =?UTF-8?q?style:=20=E5=8E=BB=E9=99=A4=20demo=20=E4=B8=AD?= =?UTF-8?q?=E5=A4=9A=E4=BD=99=E7=9A=84=E8=A1=8C=E5=B0=BE=E7=A9=BA=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- demo/ege5star.cpp | 3 +- demo/ege_new_drawimage.cpp | 29 +++++++++---------- demo/egearrow.cpp | 3 +- demo/egeball.cpp | 32 ++++++++++----------- demo/egeclock.cpp | 4 +-- demo/egegetimage.cpp | 18 ++++++------ demo/egejulia.cpp | 8 +++--- demo/egelines.cpp | 54 +++++++++++++++++------------------ demo/egerotatetransparent.cpp | 10 +++---- demo/multiplesys_edit.cpp | 14 ++++----- 10 files changed, 86 insertions(+), 89 deletions(-) diff --git a/demo/ege5star.cpp b/demo/ege5star.cpp index c60b66ed..18822b45 100644 --- a/demo/ege5star.cpp +++ b/demo/ege5star.cpp @@ -18,7 +18,6 @@ const double fullCircleRatation = PI * 2; ///< 完整圆周角度(单位:弧 const double starAngle = PI * 4 / 5; ///< 五角星角度 /** - @brief 绘制五角星 @param x 中心点 x 坐标 @param y 中心点 y 坐标 @@ -45,7 +44,7 @@ int main() r += rotatingSpeed; if (r > fullCircleRatation) r -= fullCircleRatation; - + cleardevice(); // 清空屏幕 setcolor(EGERGB(0xff, 0xff, 0xff)); // 设置绘制颜色 setfillcolor(EGERGB(0, 0, 0xff)); diff --git a/demo/ege_new_drawimage.cpp b/demo/ege_new_drawimage.cpp index 15d8f726..9f3e75e9 100644 --- a/demo/ege_new_drawimage.cpp +++ b/demo/ege_new_drawimage.cpp @@ -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; @@ -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; diff --git a/demo/egearrow.cpp b/demo/egearrow.cpp index 2822ba21..cdff8424 100644 --- a/demo/egearrow.cpp +++ b/demo/egearrow.cpp @@ -1,5 +1,5 @@ /** - + @file egearrow.cpp @brief 画箭头算法演示小程序 */ @@ -7,7 +7,6 @@ #include /** - @brief 绘制箭头 @param sx 起始点 x 坐标 @param sy 起始点 y 坐标 diff --git a/demo/egeball.cpp b/demo/egeball.cpp index ef46f664..f8b1f22c 100644 --- a/demo/egeball.cpp +++ b/demo/egeball.cpp @@ -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. */ @@ -84,7 +84,7 @@ class AniObj { ) Crash( obj[i], obj[j] ); } - + /** * @brief Draws the ball objects on the graphics window. */ @@ -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; @@ -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; } diff --git a/demo/egeclock.cpp b/demo/egeclock.cpp index cc73a6dd..ea863c5a 100644 --- a/demo/egeclock.cpp +++ b/demo/egeclock.cpp @@ -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) { diff --git a/demo/egegetimage.cpp b/demo/egegetimage.cpp index ad744bb8..d42a31b1 100644 --- a/demo/egegetimage.cpp +++ b/demo/egegetimage.cpp @@ -1,6 +1,6 @@ #include -#include -#include +#include +#include #define MSG_LEN 200 @@ -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"); @@ -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"); @@ -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"); @@ -53,10 +53,10 @@ int main() outtextxy(0, 440, msg); getch(); exit(-1); - } + } putimage(50, 50, img); delimage(img); - + getch(); closegraph(); return 0; diff --git a/demo/egejulia.cpp b/demo/egejulia.cpp index be806fd4..8b584cdb 100644 --- a/demo/egejulia.cpp +++ b/demo/egejulia.cpp @@ -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); @@ -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); diff --git a/demo/egelines.cpp b/demo/egelines.cpp index dd9aa826..16dd3026 100644 --- a/demo/egelines.cpp +++ b/demo/egelines.cpp @@ -1,10 +1,10 @@ /********************************************************************** * 文件名:egelines.cpp - * + * * 程序目的:实现变幻线屏保效果 - * + * * 使用的图形库:EGE - * + * **********************************************************************/ #include @@ -67,7 +67,7 @@ void movepoint(struct point* b) { double dv = 1.0, db = 0.5; double tw = width / 640.0, th = height / 480.0; - + if (b->x < 0) b->dx = rand_float(dv, db) * tw; if (b->y < 0) @@ -76,7 +76,7 @@ void movepoint(struct point* b) b->dx = -rand_float(dv, db) * tw; if (b->y > height) b->dy = -rand_float(dv, db) * th; - + b->x += b->dx; b->y += b->dy; } @@ -88,7 +88,7 @@ void movepoint(struct point* b) void movepoly(struct poly* p) { int i; - + for (i = 0; i < p->n_point; ++i) { movepoint(&(p->p[i])); @@ -102,15 +102,15 @@ void movepoly(struct poly* p) void movepolys(struct polys* p) { int i; - + for (i = p->n_poly - 1; i > 0; --i) { p->p[i] = p->p[i - 1]; } - + movepoly(p->p); ++(p->nowtime); - + if (--(p->time) <= 0) { p->prevcolor = p->color; @@ -119,7 +119,7 @@ void movepolys(struct polys* p) p->chtime = random(1000) + 60; p->nowtime = 0; } - + if (p->nowtime >= p->chtime) { p->color = p->nextcolor; @@ -128,11 +128,11 @@ void movepolys(struct polys* p) { double dr = p->prevcolor & 0xFF, dg = (p->prevcolor >> 8) & 0xFF, db = (p->prevcolor >> 16) & 0xFF; double dt = 1 - p->nowtime / (double)(p->chtime); - + dr -= p->nextcolor & 0xFF, dg -= (p->nextcolor >> 8) & 0xFF, db -= (p->nextcolor >> 16) & 0xFF; dr *= dt, dg *= dt, db *= dt; dr += p->nextcolor & 0xFF, dg += (p->nextcolor >> 8) & 0xFF, db += (p->nextcolor >> 16) & 0xFF; - + p->color = ((int)dr) | ((int)dg << 8) | ((int)db << 16); } } @@ -146,7 +146,7 @@ void movepolys(struct polys* p) void initpolys(struct polys* p, int npoly, int npoint) { int i, j; - + p->n_poly = npoly; p->color = 0; p->time = 1000; @@ -154,10 +154,10 @@ void initpolys(struct polys* p, int npoly, int npoint) p->nextcolor = HSVtoRGB((float)random(360), 1.0f, 0.5f); p->chtime = 1000; p->nowtime = 0; - + j = 0; p->p[j].n_point = npoint; - + for (i = 0; i < npoint; ++i) { p->p[j].p[i].x = random(width); @@ -165,7 +165,7 @@ void initpolys(struct polys* p, int npoly, int npoint) p->p[j].p[i].dx = (randomf() * 2 + 1); p->p[j].p[i].dy = (randomf() * 2 + 1); } - + for (j = 1; j < npoly; ++j) { p->p[i] = p->p[i - 1]; @@ -174,7 +174,7 @@ void initpolys(struct polys* p, int npoly, int npoint) /** * @brief - + 绘制一个多边形 * @param p 多边形对象 * @param color 颜色值 @@ -183,16 +183,16 @@ void draw_poly(struct poly* p, int color) { int points[100]; int i; - + for (i = 0; i < p->n_point; ++i) { points[i * 2] = (int)(p->p[i].x + 0.5f); points[i * 2 + 1] = (int)(p->p[i].y + 0.5f); } - + points[i * 2] = (int)(p->p[0].x + 0.5f); points[i * 2 + 1] = (int)(p->p[0].y + 0.5f); - + setcolor(color); drawpoly(p->n_point + 1, points); } @@ -214,7 +214,7 @@ int main() int n_poly[10] = {80, 40, 10, 5, 1}; int n_polys = 2, i; randomize(); - + // 图形初始化 { setinitmode(1, 0, 0); @@ -223,16 +223,16 @@ int main() height = getmaxy(); setrendermode(RENDER_MANUAL); } - + // 多边形对象初始化 for (i = 0; i < n_polys; ++i) { initpolys(&p[i], n_poly[i], n_points[i]); } - + setfont(12, 6, "宋体"); fps ui_fps; - + // 主循环 for (; is_run(); delay_fps(60)) { @@ -240,18 +240,18 @@ int main() { break; } - + for (i = 0; i < n_polys; ++i) { movepolys(&(p[i])); } - + for (i = 0; i < n_polys; ++i) { draw_polys(&(p[i])); } } - + closegraph(); return 0; } diff --git a/demo/egerotatetransparent.cpp b/demo/egerotatetransparent.cpp index e5440e26..697898c7 100644 --- a/demo/egerotatetransparent.cpp +++ b/demo/egerotatetransparent.cpp @@ -8,15 +8,15 @@ int main() setbkcolor(WHITE); setcolor( BLACK); setfillcolor( BLACK ); - - bar(50,50,600,400); - + + bar(50,50,600,400); + //image to be rotated and put PIMAGE img = newimage(200,200); setbkcolor(WHITE,img); setcolor(RED,img); setfillcolor(YELLOW,img); - + points[0]=100; points[1]=50; points[2]=50; @@ -24,7 +24,7 @@ int main() points[4]=150; points[5]=150; fillpoly(3,points,img); - + //put and rotate putimage_rotatetransparent(NULL,img,300,200,100,100,WHITE,45.0/180*PI,2); getch(); diff --git a/demo/multiplesys_edit.cpp b/demo/multiplesys_edit.cpp index 90660ece..375cba2d 100644 --- a/demo/multiplesys_edit.cpp +++ b/demo/multiplesys_edit.cpp @@ -8,7 +8,7 @@ int main() { initgraph(640, 480); setbkcolor(WHITE); - + char buffer[BUFFER_LEN+1]; sys_edit editBox; @@ -44,16 +44,16 @@ int main() } } } - + editBox.gettext(BUFFER_LEN,buffer); - + xyprintf(40, 80, buffer); - + editBox1.gettext(BUFFER_LEN,buffer); - + xyprintf(40, 180, buffer); - - + + getch(); closegraph();