C语言高逼格动态桌面壁纸编写

教育   2024-10-07 18:57   宁夏  

前言

Wallpaper Engine是一个很不错的壁纸软件,上面有很多炫酷的桌面壁纸。当然C语言使用Easyx绘图库也可以编写电脑的桌面壁纸,只需要将生成的.exe文件的后缀名改为.scr,然后就可以将这个可执行程序更换为壁纸。

启发

这里分享一些优秀的桌面壁纸先欣赏一波。

是不是看起来很炫酷。

于是我花费了国庆假期这几天,琢磨了一下。如果我设计一个动态高科技动态壁纸,该如何着手。

在我的不懈努力下,我将我以前写过的程序进行拆分组装修改,终于完成了一个属于我的桌面动态壁纸。

成果

里面所有的动态组件我前面文章中都发送过。
下面将一一列举
挑战六秒 这个主要应用了程序里面的电子数字显示,挑战六秒这个程序也是我比较满意,而且设计巧妙的程序之一。
C语言生成六十四卦 这个程序在应用的时候需要修改过字符串的类型。要注意将const char*类型的数组yiJingGuaNames修改为const wchar_t*类型。这里初始化的时候在前面加L来解决。
C语言之太极图优化 这个的程序的封装比较好,可以直接放入到任何一个程序中。
三相正弦波  这个程序是一个不错的动态演示图像。
C语言实现汉字雨 这个程序的设计也比较巧妙,但是组装到这个动态桌面的程序中使用一点小技巧,使用了SetWorkingImage这个函数,该函数我也是最近才掌握它的使用方法,感觉是一个不错的函数
C语言写一个旋转的球 这个程序非常的精妙,非常值得研究。
C语言绘制动态图 这个程序使用的是C++的类完成的。封装得也很完美。
使用C语言编写一个血条  这个程序里面使用的是字符映射表的使用,它可以输出很规范的图案。如该程序的骷髅头,世界地图,猫等等。
星罗万象时钟罗盘 这个程序是两年前我完成的。是我的满意作品之一,里面有很多值得学习的地方。
源码
///////////////////////////////////////////////////// 程序名称:动态桌面// 编译环境:Mictosoft Visual Studio 2022, EasyX_20200315(beta)// 作  者:luoyh <2864292458@qq.com>// 公 众 号:C语言研究// 最后修改:2024-10-7//
#include<graphics.h>#include<conio.h>#include<time.h>#include<math.h>
#define PI acos(-1.0)SYSTEMTIME t; //定义变量保存当前时间
void DrawYAO(int num, int x, int y); // 绘制爻void ISYD(int NUM);int Nums;void decimalToBinaryIntArray(int decimal, int binaryArray[6]);int generateRandomNumber(int min, int max);const wchar_t* yiJingGuaNames[64] ={ L"坤为地", L"地雷复", L"地水师", L"地泽临", L"地山谦", L"地火明夷", L"地风升", L"地天泰", L"雷地豫", L"震为雷", L"雷水解", L"雷泽归妹", L"雷山小过", L"雷火丰", L"雷风恒", L"雷天大壮", L"水地比", L"水雷屯", L"坎为水", L"水泽节", L"水山蹇", L"水火既济", L"水风井", L"水天需", L"泽地萃", L"泽雷随", L"泽水困", L"兑为泽", L"泽山咸", L"泽火革", L"泽风大过", L"泽天夬", L"山地剥", L"山雷颐", L"山水蒙", L"山泽损", L"艮为山", L"山火贲", L"山风蛊", L"山天大畜", L"火地晋", L"火雷噬嗑", L"火水未济", L"火泽睽", L"火山旅", L"离为火", L"火风鼎", L"火天大有", L"风地观", L"风雷益", L"风水涣", L"风泽中孚", L"风山渐", L"风火家人", L"巽为风", L"风天小畜", L"天地否", L"天雷无妄", L"天水讼", L"天泽履", L"天山遁", L"天火同人", L"天风姤", L"乾为天"};
double center_x = 445; // 圆心 x 坐标double center_y = 825; // 圆心 y 坐标double radius = 100; // 圆的半径double radians = 0;void TJ(int centerX, int centerY, int size, double angle_degrees);
int getRandom(int min, int max){ return rand() % (max - min + 1) + min;}
// Point类 class Point{public: int x, y; int xSpeed, ySpeed; int r;
Point() { r = 2; // 点的半径 x = getRandom(1330, 1580 - r); y = getRandom(530, 725 - r); xSpeed = getRandom(-3, 3); ySpeed = getRandom(-3, 3); }
void draw() { // 更新坐标 x += xSpeed; y += ySpeed;
// 超出边界回弹 if (x > 1580 - r) { x = 1580 - r; xSpeed = -xSpeed; } else if (x < 1330) { x = 1330; xSpeed = -xSpeed; } if (y > 725 - r) { y = 725 - r; ySpeed = -ySpeed; } else if (y < 530) { y = 530; ySpeed = -ySpeed; }
// 绘制点 setfillcolor(RGB(200, 200, 200)); solidcircle(x, y, r); }};
// Graph类 class Graph{private: Point* points; int pointNumber; int maxDis;
public: Graph(int pointNum = 50, int maxDistance = 30) { pointNumber = pointNum; maxDis = maxDistance; points = new Point[pointNumber]; }
~Graph() { delete[] points; }
void draw() { for (int i = 0; i < pointNumber; i++) { points[i].draw();
for (int j = i + 1; j < pointNumber; j++) { int dx = points[i].x - points[j].x; int dy = points[i].y - points[j].y; int distance = sqrt(dx * dx + dy * dy);
if (distance <= maxDis) { int NUM = 255 - static_cast<int>(distance * 255.0 / maxDis); // 确保NUM是整数 int offset = 50; setlinestyle(PS_SOLID | PS_ENDCAP_ROUND, 1); setlinecolor(RGB(NUM + offset, NUM + offset, NUM + offset)); // 当NUM接近0时,颜色接近黑色;当NUM接近255时,颜色接近白色 line(points[i].x, points[i].y, points[j].x, points[j].y); } } } }};

int CentX = 1750;int CentY = 635;// 一个圈的结构体struct TimeCircle{ int fors; // 每一圈分成的份数 int R; // 圈的半径 double NextTime; // 上一个时刻时间 double Radian; // 累加的弧度};
SYSTEMTIME ti;TimeCircle TC[7];TCHAR str[25];
// str代表绘制的字符串// variable 代表每次的变量// fors 每次需要循环的次数总数// R 该圈的半径// Radian 累加的弧度void DrawCircle(TCHAR str[25], int variable, int fors, int R, double Radian); // 绘制一圈字符 int monthdasy(int y, int m); // 某年某月的天数 y 代表年份 m 代表月份
void INITTC();void DrawALL();
void DrawBk();void DrawML(int x, int y, LPCTSTR str);void DrawMLbig();void Times(time_t start_time, long long start_times);
void DrawLG(); // 绘制骷髅头void HideSphere(float R, int alfa, int beta, int HideFlag, int X, int Y);long long current_time_millis();
void SFK(int x1, int y1, int x2, int y2); // 绘制四方括号void DrawLSX(int times); // 绘制流水线

void one(int x, int y);void two(int x, int y);void three(int x, int y);void four(int x, int y);void five(int x, int y);void six(int x, int y);void seven(int x, int y); // one 到 seven 是组成电子数字的 7 个模块void OUTNUMBER(int number, int x, int y); // 将 7 个模块组成数字 0 到 9void OUTPUT(int i, int j); // 在屏幕上显示

#define MAX_CHAR 16#define DROP_NUM 100 // 雨点数#define W 800#define H 600
struct CharDrop{ int x; int y; wchar_t ch; COLORREF color; // 颜色};
CharDrop drops[DROP_NUM][MAX_CHAR];wchar_t generate_random_chinese();// 初始化字符void InitDrop();void InitDrop(int NUM); // 带参数更新// 更新字符串void UpdataDrop();// 输出字符串void ShowDrop();

#define WIDTH 800#define HEIGHT 400#define SPEED 5 // 波形移动的速度,可调整#define GRID_SIZE 40 // 网格大小,可调整#define ARROW_SIZE 10 // 箭头大小,可调整
int phase = 0;void drawSinWave(int phaseOffset, COLORREF color);void drawGrid();void drawAxes();void DrawZS(); // 绘制装饰物
int main(){ initgraph(1900, 950); DrawBk(); time_t start_time; time(&start_time); // 获取当前时间(程序启动时间) long long start_times = current_time_millis(); INITTC();
setbkmode(TRANSPARENT); clock_t seed; seed = clock(); srand(seed); srand(time(NULL)); Graph g; InitDrop(); BeginBatchDraw(); while (true) { settextstyle(30, 0, _T("Consolas"), 0, 0, 0, false, false, false, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, DEFAULT_PITCH); Times(start_time, start_times); g.draw(); DrawALL(); //DrawLSX(start_times); UpdataDrop(); // 更新雨点 FlushBatchDraw(); cleardevice();
} EndBatchDraw();
_getch(); return 0;}

void DrawBk(){ setbkcolor(BLACK); cleardevice();
}void DrawML(int x, int y, LPCTSTR str){ setbkmode(TRANSPARENT); settextcolor(BLACK); settextstyle(30, 0, _T("Consolas")); setfillcolor(WHITE); POINT pts[] = { {x, y}, {x + 260, y}, {x + 260, y + 30},{x + 250,y + 40},{x,y + 40} }; solidpolygon(pts, 5); outtextxy(x + 10, y + 5, str);}void Times(time_t start_time, long long start_times){ // 模拟程序运行一段时间(这里用sleep函数模拟等待5秒)
time_t current_time; time(&current_time); // 获取当前时间 long long current_times = current_time_millis(); long long elapsed_times = current_times - start_times;
int elapsed_seconds = difftime(current_time, start_time); // 计算时间差(秒)
ISYD(elapsed_seconds % 64);
int days = elapsed_seconds / (60 * 60 * 24); // 计算天数(这里假设不超过一天,所以结果会是0) int hours = (elapsed_seconds % (60 * 60 * 24)) / (60 * 60); // 计算小时数 int minutes = (elapsed_seconds % (60 * 60)) / 60; // 计算分钟数 int seconds = elapsed_seconds % 60; // 计算秒数 wchar_t s[126]; swprintf_s(s, 126, L"%02d:%02d:%02d:%02d", days, hours, minutes, seconds); DrawML(30, 10, s);
GetLocalTime(&t); //获取当前时间 wchar_t s1[126]; swprintf_s(s1, 126, L"%02d:%02d:%02d:%02d:%02d", t.wMonth, t.wDay, t.wHour, t.wMinute, t.wSecond); DrawML(320, 10, s1); DrawML(1330, 10, _T("简单")); DrawML(1620, 10, _T("luoyh1207")); DrawMLbig(); DrawLG(); setlinecolor(WHITE); HideSphere(120, 45 + elapsed_times / 20, 30 + elapsed_times / 20, 1, 1460, 300); radians += 0.2; TJ(center_x, center_y, radius, radians); // 中间大的
drawGrid(); // 绘制网格 drawAxes(); // 绘制坐标轴 // 三相正弦波的相位差为120度 drawSinWave(phase, WHITE); // 第一相 drawSinWave(phase + 120, WHITE); // 第二相 drawSinWave(phase + 240, WHITE); // 第三相 phase += SPEED; // 更新相位偏移量 if (phase >= 360) // 限制相位在0到360度之间 phase = 0;
int AXXX = elapsed_seconds % 100; if (AXXX < 10) { OUTPUT(0, AXXX); } if (AXXX >= 10 && AXXX < 100) { int SW = AXXX / 10; int GW = AXXX % 10; OUTPUT(SW, GW); } DrawLSX(elapsed_times / 10); ShowDrop(); DrawZS();
settextstyle(50, 0, _T("黑体")); wchar_t s2[126]; swprintf_s(s2, 126, L"%d.%d.%d", t.wYear, t.wMonth, t.wDay); outtextxy(1375, 80, s2);}
long long current_time_millis(){ LARGE_INTEGER frequency; LARGE_INTEGER t; QueryPerformanceFrequency(&frequency); QueryPerformanceCounter(&t); return (t.QuadPart * 1000LL) / frequency.QuadPart;}
void DrawLG() // 绘制骷髅头{ setlinecolor(RGB(81, 81, 81)); setlinestyle(PS_SOLID, 1); line(30, 85, 280, 85); line(30, 250, 280, 250); line(30, 750, 280, 750);
line(320, 290, 570, 290); line(320, 720, 570, 720);
rectangle(610, 280, 1290, 730); line(1620, 360, 1875, 360); line(1620, 760, 1875, 760); line(1620, 790, 1875, 790);
line(1330, 150, 1585, 150);
line(1330, 510, 1585, 510);
line(1330, 745, 1585, 745);
for (int i = 0; i < 22; i++) { line(1330, 175 + 15 * i, 1585, 175 + 15 * i); }
settextcolor(RGB(81, 81, 81)); settextstyle(100, 0, _T("宋体")); outtextxy(1500, 300, _T("簡")); outtextxy(1500, 400, _T("單"));
SFK(315, 580, 580, 695); SFK(1325, 530, 1585, 730); SFK(1620, 80, 1880, 280); SFK(1620, 520, 1880, 750);
settextstyle(250, 0, _T("Wingdings")); wchar_t c = 0x4E; settextcolor(WHITE); RECT r = { 1620,80,1880,280 }; drawtext(c, &r, DT_CENTER | DT_VCENTER | DT_SINGLELINE);}

void HideSphere(float R, int alfa, int beta, int HideFlag, int X, int Y){ int i, j, k; float x[4], y[4], z[4], x1[4], y1[4], z1[4], sx[4], sy[4]; double a1, a2, b1, b2, c, d, xn, yn, zn, vn; c = alfa * PI / 180.0; d = beta * PI / 180.0; for (j = 0; j < 180; j = j + 5) { a1 = j * PI / 180.0; a2 = (j + 5) * PI / 180.0; for (i = 0; i < 360; i = i + 5) { b1 = i * PI / 180.0; b2 = (i + 5) * PI / 180.0; x[0] = R * sin(a1) * cos(b1); y[0] = R * sin(a1) * sin(b1); z[0] = R * cos(a1); x[1] = R * sin(a2) * cos(b1); y[1] = R * sin(a2) * sin(b1); z[1] = R * cos(a2); x[2] = R * sin(a2) * cos(b2); y[2] = R * sin(a2) * sin(b2); z[2] = R * cos(a2); x[3] = R * sin(a1) * cos(b2); y[3] = R * sin(a1) * sin(b2); z[3] = R * cos(a1); for (k = 0; k < 4; k++) { x1[k] = x[k] * cos(c) - y[k] * sin(c); y1[k] = x[k] * sin(c) * cos(d) + y[k] * cos(c) * sin(d) + z[k] * sin(d); z1[k] = -x[k] * sin(c) * sin(d) - y[k] * cos(c) * sin(d) + z[k] * cos(d); sx[k] = X - x1[k]; sy[k] = Y - z1[k]; } xn = (y1[2] - y1[0]) * (z1[3] - z1[1]) - (y1[3] - y1[1]) * (z1[2] - z1[0]); yn = -(x1[2] - x1[0]) * (z1[3] - z1[1]) + (x1[3] - x1[1]) * (z1[2] - z1[0]); zn = (x1[2] - x1[0]) * (y1[3] - y1[1]) - (x1[3] - x1[1]) * (y1[2] - y1[0]); vn = sqrt(xn * xn + yn * yn + zn * zn); xn = xn / vn; yn = yn / vn; zn = zn / vn; if (!HideFlag || yn >= 0.0) { moveto(sx[0], sy[0]); lineto(sx[1], sy[1]); lineto(sx[2], sy[2]); lineto(sx[3], sy[3]); lineto(sx[0], sy[0]); } } }}
void DrawMLbig(){ setbkmode(TRANSPARENT); settextcolor(BLACK); settextstyle(45, 0, _T("黑体")); setfillcolor(WHITE); POINT pts[] = { {610, 10}, {905, 10}, {905, 55},{895,65},{610,65} }; solidpolygon(pts, 5); outtextxy(610 + 70, 10 + 5, _T("C语言研究")); settextstyle(30, 0, _T("Consolas")); solidrectangle(980, 10, 1050, 40); outtextxy(980 + 5, 10 + 2, _T("1207"));}
void SFK(int x1, int y1, int x2, int y2){ setlinecolor(RGB(81, 81, 81)); setlinestyle(PS_SOLID, 1);
line(x1, y1, x1 + 10, y1); line(x1, y1, x1, y1 + 10);
line(x2, y2, x2 - 10, y2); line(x2, y2, x2, y2 - 10);
line(x1, y2, x1 + 10, y2); line(x1, y2, x1, y2 - 10);
line(x2, y1, x2 - 10, y1); line(x2, y1, x2, y1 + 10);}

void INITTC(){ for (int i = 0; i < 7; i++) { TC[i].R = (i + 1) * 15; TC[i].Radian = 0; TC[i].NextTime = 0;
switch (i) { case 0:TC[i].fors = 1; break; // 年 case 1:TC[i].fors = 12; break; // 月 case 2:TC[i].fors = 30; break; // 日 case 3:TC[i].fors = 7; break; // 周 case 4:TC[i].fors = 24; break; // 时 case 5:TC[i].fors = 60; break; // 分 case 6:TC[i].fors = 60; break; // 秒 } }}int monthdasy(int y, int m){ if (m == 2) return ((y % 4 == 0 && y % 100 != 0) || y % 400 == 0) ? 29 : 28; else return 31 - (m - 3) % 5 % 2;}
void DrawCircle(TCHAR str[25], int variable, int fors, int R, double Radian){ //settextcolor(variable ? HSLtoRGB((360.f / fors) * variable, 1, 0.5f) : WHITE); double a, x0, y0, w, h, x1, y1; int x, y; settextstyle(8, 0, L"微软雅黑", variable * 3600 / fors, variable * 3600 / fors, 0, false, false, false, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, DEFAULT_PITCH);
a = (fors == 60) ? ((variable + 1) * PI * 2 / fors - Radian) : (variable * PI * 2 / fors); // 计算字符串弧度 a
w = textwidth(str); // 计算字符串宽 w、高 h h = textheight(str);
x1 = R * cos(a); // 计算输出字符串的左上角位置 y1 = R * sin(a);
x0 = x1 * cos(-a) - y1 * sin(-a); // 将字符串绕原点顺时针旋转 a 弧度 y0 = y1 * cos(-a) + x1 * sin(-a);
x0 -= w / 2; // 将字符串向左上偏移 w/2、h/2 y0 += h / 2; // 绘图坐标向下为正
x = (int)(x0 * cos(a) - y0 * sin(a)); // 将字符串绕原点逆时针旋转 a 弧度 y = (int)(y0 * cos(a) + x0 * sin(a)); settextcolor(WHITE); outtextxy(int(CentX + x + 0.5), int(CentY - y + 0.5), str); // 绘图坐标向下为正}
void DrawALL(){ GetLocalTime(&ti); TC[2].fors = monthdasy(ti.wYear, ti.wMonth); for (int j = 0; j < 7; j++) { if (TC[5].NextTime != ti.wMinute) { TC[5].NextTime = ti.wMinute; TC[5].Radian = 0; } else { TC[5].Radian = TC[5].Radian + (2 * PI / TC[5].fors - TC[5].Radian) / 10; }
if (TC[6].NextTime != ti.wSecond) { TC[6].NextTime = ti.wSecond; TC[6].Radian = 0; } else { TC[6].Radian = TC[6].Radian + (2 * PI / TC[6].fors - TC[6].Radian) / 10; }
for (int i = 0; i < TC[j].fors; i++) { switch (j) { case 0: _stprintf_s(str, _T("%d年"), ti.wYear); break; case 1: _stprintf_s(str, _T("%d月"), (i + ti.wMonth) % TC[j].fors ? (i + ti.wMonth) % TC[j].fors : TC[j].fors); break; case 2: _stprintf_s(str, _T("%d号"), (i + ti.wDay) % TC[j].fors ? (i + ti.wDay) % TC[j].fors : i + ti.wDay); break; case 3: str[0] = L"周"[0]; str[1] = L"日一二三四五六"[(i + ti.wDayOfWeek) % 7]; str[2] = L""[0]; break; case 4: _stprintf_s(str, _T("%d时"), (i + ti.wHour) % TC[j].fors); break; case 5: _stprintf_s(str, _T("%d分"), (i + ti.wMinute) % TC[j].fors); break; case 6: _stprintf_s(str, _T("%d秒"), (i + ti.wSecond) % TC[j].fors); break; } DrawCircle(str, i, TC[j].fors, TC[j].R, TC[j].Radian);; } }}
void DrawLSX(int times){ IMAGE img(240, 240); SetWorkingImage(&img); setlinestyle(PS_SOLID, 10); int A = times % 70; for (int i = 0; i < 10; i++) { line(0 - 240 + A + 70 * i, 0, -240 - 240 + A + 70 * i, 240); } SetWorkingImage(); putimage(20, 405, &img);
IMAGE img1(320, 70); SetWorkingImage(&img1); setlinestyle(PS_SOLID, 10); for (int i = 0; i < 10; i++) { line(0 - 240 + A + 70 * i, 0, -240 - 240 + A + 70 * i, 240); } SetWorkingImage(); putimage(975, 50, &img1);

}
void one(int x, int y){ int pts[] = { 36 + x, 14 + y, 59 + x, 39 + y, 118 + x, 39 + y, 138 + x, 15 + y, 131 + x, 9 + y, 41 + x, 9 + y }; //setfillcolor(RGB(176, 215, 254)); setfillcolor(WHITE); solidpolygon((POINT*)pts, 6);}
void two(int x, int y){ int pts[] = { 32 + x, 17 + y, 53 + x, 40 + y, 47 + x, 96 + y, 26 + x, 113 + y, 18 + x, 102 + y, 25 + x, 27 + y }; //setfillcolor(RGB(184, 249, 251)); setfillcolor(WHITE); solidpolygon((POINT*)pts, 6);}
void three(int x, int y){ int pts[] = { 143 + x, 20 + y, 152 + x, 31 + y, 144 + x, 105 + y, 132 + x, 115 + y, 115 + x, 98 + y, 122 + x, 41 + y, }; //setfillcolor(RGB(187, 250, 255)); setfillcolor(WHITE); solidpolygon((POINT*)pts, 6);}
void four(int x, int y){ int pts[] = { 46 + x, 101 + y, 113 + x, 101 + y, 127 + x, 116 + y, 111 + x, 131 + y, 45 + x, 131 + y, 29 + x, 117 + y }; //setfillcolor(RGB(187, 254, 219)); setfillcolor(WHITE); solidpolygon((POINT*)pts, 6);}
void five(int x, int y){ int pts[] = { 25 + x, 120 + y, 43 + x, 136 + y, 38 + x, 199 + y, 15 + x, 223 + y, 6 + x, 209 + y, 15 + x, 127 + y }; //setfillcolor(RGB(245, 255, 192)); setfillcolor(WHITE); solidpolygon((POINT*)pts, 6);}
void six(int x, int y){ int pts[] = { 132 + x, 119 + y, 144 + x, 128 + y, 136 + x, 213 + y, 129 + x, 222 + y, 107 + x, 201 + y, 115 + x, 134 + y }; //setfillcolor(RGB(245, 255, 190)); setfillcolor(WHITE); solidpolygon((POINT*)pts, 6);}
void seven(int x, int y){ int pts[] = { 40 + x, 203 + y, 104 + x, 203 + y, 126 + x, 226 + y, 120 + x, 231 + y, 24 + x, 231 + y, 18 + x, 226 + y }; //setfillcolor(RGB(251, 221, 185)); setfillcolor(WHITE); solidpolygon((POINT*)pts, 6);}
void OUTNUMBER(int number, int x, int y){ switch (number) { case 0:one(x, y); three(x, y); six(x, y); seven(x, y); five(x, y); two(x, y); break; case 1:three(x, y); six(x, y); break; case 2:one(x, y); three(x, y); four(x, y); five(x, y); seven(x, y); break; case 3:one(x, y); three(x, y); four(x, y); six(x, y); seven(x, y); break; case 4:two(x, y); three(x, y); four(x, y); six(x, y); break; case 5:one(x, y); two(x, y); four(x, y); six(x, y); seven(x, y); break; case 6:one(x, y); two(x, y); four(x, y); six(x, y); seven(x, y); five(x, y); break; case 7:one(x, y); three(x, y); six(x, y); break; case 8:one(x, y); three(x, y); six(x, y); seven(x, y); five(x, y); two(x, y); four(x, y); break; case 9:one(x, y); three(x, y); six(x, y); seven(x, y); two(x, y); four(x, y); break; }}
void OUTPUT(int i, int j){ OUTNUMBER(i, 300, 50); OUTNUMBER(j, 435, 50);}
wchar_t generate_random_chinese(){ wchar_t base = L'一'; // 汉字编码起始值 wchar_t offset = rand() % 20902; // 汉字编码总数 return base + offset;}void InitDrop(){ for (int j = 0; j < DROP_NUM; j++) { // 生成一个X坐标 int x = (rand() % (W - 1 + 1)) + 1; // 生成一个Y坐标 int y = (rand() % (0 - (-800) + 1)) - 800; for (int i = 0; i < MAX_CHAR; i++) { drops[j][i].x = x; drops[j][i].y = y - i * 10; drops[j][i].ch = generate_random_chinese(); // Random number or character if (i == 0) { drops[j][i].color = WHITE; } else { double dx = MAX_CHAR; // 颜色分级 double redStep = (GetRValue(BLACK) - GetRValue(WHITE)) / dx; double greenStep = (GetGValue(BLACK) - GetGValue(WHITE)) / dx; double blueStep = (GetBValue(BLACK) - GetBValue(WHITE)) / dx;
drops[j][i].color = RGB(GetRValue(WHITE) + i * redStep, GetGValue(WHITE) + i * greenStep, GetBValue(WHITE) + i * blueStep); } } drops[j][MAX_CHAR - 1].color = BLACK; }}
void InitDrop(int j) // 带参数更新{ // 生成一个X坐标 int x = (rand() % (W - 1 + 1)) + 1; // 生成一个Y坐标 int y = (rand() % (0 - (-800) + 1)) - 800; for (int i = 0; i < MAX_CHAR; i++) { drops[j][i].x = x; drops[j][i].y = y - i * 10; drops[j][i].ch = generate_random_chinese(); // Random number or character if (i == 0) { drops[j][i].color = WHITE; } else { double dx = MAX_CHAR; // 颜色分级 double redStep = (GetRValue(BLACK) - GetRValue(WHITE)) / dx; double greenStep = (GetGValue(BLACK) - GetGValue(WHITE)) / dx; double blueStep = (GetBValue(BLACK) - GetBValue(WHITE)) / dx;
drops[j][i].color = RGB(GetRValue(WHITE) + i * redStep, GetGValue(WHITE) + i * greenStep, GetBValue(WHITE) + i * blueStep); } } drops[j][MAX_CHAR - 1].color = BLACK;}
void ShowDrop(){ IMAGE img(670, 445); // 设置绘图目标为 img 对象 SetWorkingImage(&img); settextstyle(10, 0, _T("隶书")); for (int j = 0; j < DROP_NUM; j++) { for (int i = 0; i < MAX_CHAR; i++) { settextcolor(drops[j][i].color); outtextxy(drops[j][i].x, drops[j][i].y, drops[j][i].ch); } } SetWorkingImage(); // 将 img 对象显示在绘图窗口中 putimage(620, 285, &img);}
void UpdataDrop(){ for (int j = 0; j < DROP_NUM; j++) { for (int i = MAX_CHAR - 1; i > 0; i--) { drops[j][i].x = drops[j][i].x; drops[j][i].y = drops[j][i].y + 10; drops[j][i].ch = drops[j][i - 1].ch; } drops[j][0].x = drops[j][0].x; drops[j][0].y = drops[j][0].y + 10; drops[j][0].ch = generate_random_chinese(); drops[j][0].color = WHITE; if (drops[j][MAX_CHAR - 1].y > H) { InitDrop(j); } }}
void ISYD(int NUM){ settextcolor(WHITE); settextstyle(60, 0, _T("楷体")); setbkmode(TRANSPARENT); RECT r = { 315,580,575,695 }; drawtext(yiJingGuaNames[NUM], &r, DT_CENTER | DT_VCENTER | DT_SINGLELINE); int binaryArray[6]; // 整数数组,但每个元素只存储一个二进制位 decimalToBinaryIntArray(NUM, binaryArray); for (int i = 5; i >= 0; i--) { DrawYAO(binaryArray[i], 350, 530 - i * 40); }}
int generateRandomNumber(int min, int max){ // 确保max大于等于min if (max < min) { int temp = min; min = max; max = temp; } // 使用rand()生成随机数,并通过取模确保结果在min到max之间 int random = rand() % (max - min + 1) + min; return random;}
void DrawYAO(int num, int x, int y){ setfillcolor(WHITE); if (num == 1) { solidrectangle(x, y, x + 200, y + 20); // 二进制为1时,绘制长实线 } if (num == 0) { solidrectangle(x, y, x + 100 - 10, y + 20); // 二进制为0时,绘制短实线 solidrectangle(x + 100 + 10, y, x + 200, y + 20); }}
// 将一个十进制数转换为二进制存储到数组中void decimalToBinaryIntArray(int decimal, int binaryArray[6]){ for (int i = 0; i < 6; i++) { // 从最低位开始填充 binaryArray[i] = decimal % 2; decimal /= 2; }}
void TJ(int centerX, int centerY, int size, double radians){ setfillcolor(BLACK); solidpie(centerX - size, centerY - size, centerX + size, centerY + size, radians, radians + PI); setfillcolor(WHITE); solidpie(centerX - size, centerY - size, centerX + size, centerY + size, radians + PI, radians); // 使用弧度计算坐标 int x1 = centerX + size / 2.0 * cos(-radians); int y1 = centerY + size / 2.0 * sin(-radians); int x2 = centerX + size / 2.0 * cos(-(radians + PI)); int y2 = centerY + size / 2.0 * sin(-(radians + PI)); setfillcolor(WHITE); solidcircle(x1, y1, size / 2); setfillcolor(BLACK); solidcircle(x2, y2, size / 2); // 绘制鱼眼 setfillcolor(BLACK); solidcircle(x1, y1, size / 10); setfillcolor(WHITE); solidcircle(x2, y2, size / 10);}
void drawSinWave(int phaseOffset, COLORREF color){ for (int x = 620; x < 1280; x++) { double y = sin((x + phaseOffset) * PI / 180) * HEIGHT / 6 + HEIGHT / 2; putpixel(x, y, color); }}
void drawGrid(){ setlinecolor(RGB(51, 51, 51)); setlinestyle(PS_DOT, 1); // 绘制横向网格线 for (int y = 120; y <= 300; y += GRID_SIZE) { line(620, y, 1300, y); }
// 绘制纵向网格线 for (int x = 620; x <= 1300; x += GRID_SIZE) { line(x, 120, x, 282); }}
void drawAxes(){ setcolor(WHITE); settextstyle(10, 0, _T("宋体")); setlinestyle(PS_SOLID, 1); setbkmode(TRANSPARENT); // 绘制横轴箭头 line(620, HEIGHT / 2, 1280, HEIGHT / 2); line(1280 - ARROW_SIZE, HEIGHT / 2 - ARROW_SIZE, 1280, HEIGHT / 2); line(1280 - ARROW_SIZE, HEIGHT / 2 + ARROW_SIZE, 1280, HEIGHT / 2); settextcolor(WHITE); // 标注横轴刻度值 for (int x = 620; x <= 1280; x += GRID_SIZE) { TCHAR str[5]; _stprintf_s(str, 5, L"%d", x - WIDTH / 2); outtextxy(x, HEIGHT / 2 + ARROW_SIZE + 5, str); }}
void DrawZS(){ setfillcolor(WHITE); solidrectangle(220, 220, 280, 235); solidrectangle(610, 100, 630, 120); solidrectangle(1330, 80, 1370, 130); solidrectangle(1620, 310, 1630, 320);
setlinecolor(WHITE); setlinestyle(PS_SOLID | PS_ENDCAP_SQUARE, 1); rectangle(1327, 410, 1397, 480); line(1327, 410, 1397, 480); setlinecolor(RGB(170, 170, 170)); setlinestyle(PS_SOLID | PS_ENDCAP_SQUARE, 1); line(26, 688, 280, 688);
setlinecolor(RGB(204, 204, 204)); setlinestyle(PS_SOLID | PS_ENDCAP_SQUARE, 4); line(26, 696, 280, 696); line(1620, 770, 1875, 770);
settextstyle(150, 0, _T("Webdings")); wchar_t c = 0xFB; settextcolor(WHITE); RECT r = { 1620,360,1880,500 }; drawtext(c, &r, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
wchar_t c1 = 0xF6; settextcolor(RGB(120, 120, 120)); RECT r1 = { 40,760,280,920 }; drawtext(c1, &r1, DT_CENTER | DT_VCENTER | DT_SINGLELINE);

settextstyle(50, 0, _T("Wingdings")); wchar_t c2 = 0xCB; wchar_t c3 = 0xCD; wchar_t c4 = 0xCE; wchar_t c5 = 0xCF; wchar_t c6 = 0xD0; settextcolor(WHITE); int SSS = 1330; int SJG = 50; outtextxy(SSS, 780, c2); SSS += SJG; outtextxy(SSS, 780, c3); SSS += SJG; outtextxy(SSS, 780, c4); SSS += SJG; outtextxy(SSS, 780, c5); SSS += SJG; outtextxy(SSS, 780, c6);
settextstyle(50, 0, _T("Wingdings 2")); wchar_t c7 = 0x59; wchar_t c8 = 0x5A; wchar_t c9 = 0x5B; wchar_t c10 = 0x5C;
SSS = 1620; SJG = 50; outtextxy(SSS, 815, c7); SSS += SJG; outtextxy(SSS, 815, c9); SSS += SJG; outtextxy(SSS, 815, c8); SSS += SJG; outtextxy(SSS, 815, c10);

settextcolor(RGB(137, 137, 137)); settextstyle(20, 0, _T("微软雅黑"));
int STARX = 640; int LEJ = 50; int JGY = 40; int STARY = 750;
outtextxy(STARX, STARY, _T("ESC")); STARX += LEJ; outtextxy(STARX, STARY, _T("1")); STARX += LEJ; outtextxy(STARX, STARY, _T("2")); STARX += LEJ; outtextxy(STARX, STARY, _T("3")); STARX += LEJ; outtextxy(STARX, STARY, _T("4")); STARX += LEJ; outtextxy(STARX, STARY, _T("5")); STARX += LEJ; outtextxy(STARX, STARY, _T("6")); STARX += LEJ; outtextxy(STARX, STARY, _T("7")); STARX += LEJ; outtextxy(STARX, STARY, _T("8")); STARX += LEJ; outtextxy(STARX, STARY, _T("9")); STARX += LEJ; outtextxy(STARX, STARY, _T("0")); STARX += LEJ; outtextxy(STARX, STARY, _T("BACK"));
STARX = 655; STARY += JGY; outtextxy(STARX, STARY, _T("TAB")); STARX += LEJ; outtextxy(STARX, STARY, _T("Q")); STARX += LEJ; outtextxy(STARX, STARY, _T("W")); STARX += LEJ; outtextxy(STARX, STARY, _T("E")); STARX += LEJ; outtextxy(STARX, STARY, _T("R")); STARX += LEJ; outtextxy(STARX, STARY, _T("T")); STARX += LEJ; outtextxy(STARX, STARY, _T("Y")); STARX += LEJ; outtextxy(STARX, STARY, _T("U")); STARX += LEJ; outtextxy(STARX, STARY, _T("I")); STARX += LEJ; outtextxy(STARX, STARY, _T("O")); STARX += LEJ; outtextxy(STARX, STARY, _T("P"));
STARX = 670; STARY += JGY; outtextxy(STARX, STARY, _T("CAPS")); STARX += LEJ; outtextxy(STARX, STARY, _T("A")); STARX += LEJ; outtextxy(STARX, STARY, _T("S")); STARX += LEJ; outtextxy(STARX, STARY, _T("D")); STARX += LEJ; outtextxy(STARX, STARY, _T("F")); STARX += LEJ; outtextxy(STARX, STARY, _T("G")); STARX += LEJ; outtextxy(STARX, STARY, _T("H")); STARX += LEJ; outtextxy(STARX, STARY, _T("J")); STARX += LEJ; outtextxy(STARX, STARY, _T("K")); STARX += LEJ; outtextxy(STARX, STARY, _T("L")); STARX += LEJ; outtextxy(STARX, STARY, _T(":")); STARX += LEJ; outtextxy(STARX, STARY, _T("ENTER"));
STARX = 650; STARY += JGY; outtextxy(STARX, STARY, _T("SHIFT")); STARX += LEJ; outtextxy(STARX, STARY, _T("Z")); STARX += LEJ; outtextxy(STARX, STARY, _T("X")); STARX += LEJ; outtextxy(STARX, STARY, _T("C")); STARX += LEJ; outtextxy(STARX, STARY, _T("V")); STARX += LEJ; outtextxy(STARX, STARY, _T("B")); STARX += LEJ; outtextxy(STARX, STARY, _T("N")); STARX += LEJ; outtextxy(STARX, STARY, _T("M")); STARX += LEJ; outtextxy(STARX, STARY, _T(",")); STARX += LEJ; outtextxy(STARX, STARY, _T(".")); STARX += LEJ; outtextxy(STARX, STARY, _T("#")); STARX += LEJ; outtextxy(STARX, STARY, _T("SHIFT"));
setlinecolor(RGB(128, 128, 128)); setlinestyle(PS_SOLID | PS_ENDCAP_SQUARE, 1); rectangle(780, 925, 1120, 945);
settextcolor(WHITE); settextstyle(10, 0, _T("微软雅黑"));
STARX = 262; STARY = 403; int JG = 40; outtextxy(STARX, STARY, _T("0.07")); STARY += JG; outtextxy(STARX, STARY, _T("0.06")); STARY += JG; outtextxy(STARX, STARY, _T("0.05")); STARY += JG; outtextxy(STARX, STARY, _T("0.04")); STARY += JG; outtextxy(STARX, STARY, _T("0.03")); STARY += JG; outtextxy(STARX, STARY, _T("0.02")); STARY += JG; outtextxy(STARX, STARY, _T("0.01"));
STARX = 40; STARY = 666; JG = 50; outtextxy(STARX, STARY, _T("0.1")); STARX += JG; outtextxy(STARX, STARY, _T("0.2")); STARX += JG; outtextxy(STARX, STARY, _T("0.3")); STARX += JG; outtextxy(STARX, STARY, _T("0.4")); STARX += JG; outtextxy(STARX, STARY, _T("0.5"));
STARX = 1620; STARY = 335; JG = 35; outtextxy(STARX, STARY, _T("0")); STARX += JG; outtextxy(STARX, STARY, _T("20")); STARX += JG; outtextxy(STARX, STARY, _T("40")); STARX += JG; outtextxy(STARX, STARY, _T("60")); STARX += JG; outtextxy(STARX, STARY, _T("100")); //settextcolor(WHITE); settextstyle(30, 0, _T("黑体")); outtextxy(25, 820, _T("公众号:C语言研究"));
settextstyle(10, 0, _T("黑体")); outtextxy(25, 870, _T("写给自己的笔记")); outtextxy(25, 885, _T("时常写写")); outtextxy(25, 900, _T("时常看看")); outtextxy(25, 915, _T("仅此而已")); outtextxy(1635, 310, _T("登高必自卑,行远必自迩。")); outtextxy(728, 85, _T("专注于C语言领域的研究以及Easyx绘图库的使用")); settextstyle(45, 0, _T("宋体")); outtextxy(25, 120, _T("LUO_YIN_")); outtextxy(25, 170, _T("HU.1207"));}

结语

你居然都翻到最底下了,是不是企图读懂我深奥的思想,哈哈哈哈哈。

代码比较长,而且比较琐碎。虽然最终完成了我想要的效果,但是维护起来会很麻烦。如果想要进一步优化和修改,可以将这代码分解为几个.h和.cpp文件。

登高必自卑,行远必自迩。如果能看到这句话,说明你很有耐心,为你和我的耐心点个赞,愿我们在编程的路上越走越远。

C语言研究
写给自己的笔记,时常写写,时常看看,仅此而已。