其实就是个椭圆。
效果图:
代码
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<easyx.h>
#include<math.h>
#include<time.h>
#include<mmsystem.h>
#include<chrono>
#pragma comment(lib, "winmm.lib")
using namespace std;
ExMessage msg = { 0 };
bool inArea(int mx, int my, int x, int y, int w, int h)
{
return mx >= x && mx <= x + w && my >= y && my <= y + h;
}
bool button(int x, int y, int w, int h, const char* text)
{
if (inArea(msg.x, msg.y, x, y, w, h))
setfillcolor(RGB(93, 107, 153));
else
setfillcolor(RGB(230, 231, 232));
fillroundrect(x, y, x + w, y + h, 5, 5);
int hSpace = (w - textwidth(text)) / 2;
int vSpace = (h - textheight(text)) / 2;
outtextxy(x + hSpace, y + vSpace, text);
if (msg.message == WM_LBUTTONDOWN && inArea(msg.x, msg.y, x, y, w, h))
{
return true;
}
return false;
}
int main()
{
initgraph(800, 600);
setbkcolor(WHITE);
cleardevice();
setbkmode(TRANSPARENT);
settextcolor(BLACK);
while (true)
{
peekmessage(&msg, EX_MOUSE | EX_KEY);
if (msg.message == WM_KEYDOWN)
{
if (msg.vkcode == VK_ESCAPE)
return 0;
}
BeginBatchDraw();
if (button(300, 200, 200, 50, "开始旋转炸鸡块"))
break;
if (button(300, 300, 200, 50, "按ESC键退出"))
return 0;
EndBatchDraw();
}
auto start_time = chrono::high_resolution_clock::now();
mciSendString("open static/FunkyTown.mp3 alias BGM", NULL, 0, NULL);
mciSendString("play BGM repeat", NULL, 0, NULL);
setbkcolor(WHITE);
cleardevice();
setfillcolor(YELLOW);
int left, top, right, bottom;
while (true)
{
peekmessage(&msg, EX_MOUSE | EX_KEY);
if (msg.message == WM_KEYDOWN)
{
if (msg.vkcode == VK_ESCAPE)
break;
}
cleardevice();
clock_t t1 = clock();
top = 200 + 25 * sin(t1);
bottom = 400 + 25 * sin(t1);
clock_t t2 = clock();
left = min(400 + 50 * sin(t2), 400 - 50 * sin(t2));
right = max(400 + 50 * sin(t2), 400 - 50 * sin(t2));
BeginBatchDraw();
auto now_time = chrono::high_resolution_clock::now();
auto duration = chrono::duration_cast<chrono::milliseconds>(now_time - start_time);
char str[100];
int hour = duration.count() / 1000 / 60 / 60;
int minute = duration.count() / 1000 / 60 % 60;
int second = duration.count() / 1000 % 60;
sprintf(str, "%02d:%02d:%02d", hour, minute, second);
settextcolor(BLACK);
outtextxy(10, 10, str);
solidellipse(left, top, right, bottom);
EndBatchDraw();
}
mciSendString("close BGM", NULL, 0, NULL);
closegraph();
return 0;
}
我就不信有人会在AcWing里搜旋转鸡块(