easyX运动简易自行车

这段代码演示了如何使用easyX库在窗口中创建一个简易自行车的动画效果。通过循环改变坐标,实现自行车组件沿x轴的平移运动,同时配合Sleep函数控制动画速度。
摘要由CSDN通过智能技术生成

int main(void)
{
int x, x1, y1, x2, y2,n;
int bkcolor = WHITE;//背景颜色
initgraph(1200, 1200);//窗口大小
setbkcolor(bkcolor);//窗口颜色
cleardevice();//调用cleardevice,背景色刷新背景
//与x轴有关的线,圆,长方形,进行运动
for (x = 50; x < 1000; x += 10) {
setcolor(BLACK);
setfillcolor(LIGHTGRAY);
x1 = x + 60;
y1 = 370;
x2 = x + 100;
y2 = 375;
n = 5;
setlinestyle(PS_SOLID, n);//设置线的宽度
circle(x, 500, 60);
circle(x, 500, 12);
fillcircle(x, 500, 10);
circle(x + 160, 470, 20);
fillcircle(x + 160, 470, 18);
circle(x + 300, 500, 60);
circle(x + 300, 500, 12);
fillcircle(x + 300, 500, 10);
line(x + 9, 490, x + 142, 470);
line(x + 170, 485, x + 190, 520);
line(x + 185, 520, x + 195, 520);
line(x + 300, 488, x + 280, 420);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我可以帮您设计一个基于EasyX图形库简易登录界面。以下是一个示例代码: ```cpp #include <graphics.h> #include <conio.h> #include <iostream> #include <cstring> using namespace std; int main() { // 初始化图形界面 initgraph(400, 300); // 绘制登录框 setfillcolor(WHITE); setlinecolor(BLACK); roundrect(100, 50, 300, 200, 10, 10); // 绘制标题 settextcolor(BLACK); settextstyle(25, 0, _T("微软雅黑")); outtextxy(150, 75, _T("欢迎使用")); // 绘制用户名和密码输入框 settextstyle(15, 0, _T("微软雅黑")); outtextxy(120, 110, _T("用户名:")); outtextxy(120, 150, _T("密 码:")); setlinecolor(BLACK); rectangle(200, 100, 280, 130); rectangle(200, 140, 280, 170); // 绘制登录按钮 setfillcolor(RGB(0, 162, 232)); setlinecolor(BLACK); roundrect(150, 190, 250, 230, 5, 5); settextcolor(WHITE); settextstyle(20, 0, _T("微软雅黑")); outtextxy(180, 200, _T("登录")); // 循环等待用户输入 char username[20] = ""; char password[20] = ""; int cursorX = 205; int cursorY = 105; bool isUsernameInputting = true; while (true) { if (_kbhit()) { char ch = _getch(); if (ch == '\r') // 用户按下回车键,尝试登录 { // 进行用户名和密码的验证,这里只是简单的比较字符串 if (strcmp(username, "admin") == 0 && strcmp(password, "123456") == 0) { settextcolor(GREEN); outtextxy(160, 250, _T("登录成功")); Sleep(2000); // 等待2秒后退出程序 break; } else { settextcolor(RED); outtextxy(160, 250, _T("用户名或密码错误")); } } else if (ch == '\b') // 用户按下退格键,删除输入框中的一个字符 { if (isUsernameInputting) { if (strlen(username) > 0) { username[strlen(username) - 1] = '\0'; cursorX -= 8; } } else { if (strlen(password) > 0) { password[strlen(password) - 1] = '\0'; cursorX -= 8; } } } else if (ch == '\t') // 用户按下Tab键,切换输入框 { isUsernameInputting = !isUsernameInputting; if (isUsernameInputting) { cursorX = 205; cursorY = 105; } else { cursorX = 205; cursorY = 145; } } else if (strlen(username) < 18 || strlen(password) < 18) // 用户输入字符 { if (isUsernameInputting) { strcat(username, &ch); outtextxy(cursorX, cursorY, &ch); cursorX += 8; } else { strcat(password, &ch); outtextxy(cursorX, cursorY, _T("*")); cursorX += 8; } } } } // 关闭图形界面 closegraph(); return 0; } ``` 运行上述代码,即可看到一个简易的登录界面。用户可以在用户名和密码输入框中输入内容,并通过按下回车键进行登录验证。如果用户名或密码错误,会在界面下方提示错误信息。如果登录成功,会在界面下方提示登录成功,并等待2秒后退出程序。 需要注意的是,以上代码只是一个简单的示例,真实的登录界面可能需要进行更复杂的验证,比如连接到数据库进行账号验证等等。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值