Easyx 学习记录

1. 创建小球

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-xgq8oN2i-1655694620229)(https://i.loli.net/2021/10/23/8nHWEmclvKD6CFr.png)]

#include <iostream>
#include <graphics.h>
#include <conio.h>
#include <stdio.h>
int main()
{initgraph(600, 600);fillcircle(400, 120,50);//北fillcircle(320, 200, 50);//西fillcircle(400,200, 25);//中fillcircle(480, 200, 50);//东fillcircle(400, 280, 50);//南_getch();//和getchar一样closegraph();return 0;
}

采用常量可以使我们的代码的健壮性增强,易于维护和修改

#include <iostream>
#include <graphics.h>
#include <conio.h>
#include <stdio.h>const int x = 300, y = 200, mid_radius = 25,others_radius = 50;int main()
{initgraph(600, 600);fillcircle(x, y-80,others_radius);//北fillcircle(x-80, y, others_radius);//西fillcircle(x,y, mid_radius);//中fillcircle(x+80, y, others_radius);//东fillcircle(x, y+80, others_radius);//南_getch();closegraph();return 0;
}

2. 实现小球匀速下滑

EasyX 白色小球 匀速下滑动画_哔哩哔哩_bilibili

#include <iostream>
#include <graphics.h>
#include <conio.h>
#include <stdio.h>
int main()
{initgraph(600, 600);int cnt = 0;int x = 300, y = 100, r = 50;while (++cnt < 500) {fillcircle(x, y, r);y += 10;Sleep(200);cleardevice();}_getch();closegraph();return 0;
}

3. 小球往返运动

EasyX 小球匀速往返运动_哔哩哔哩_bilibili

#include <iostream>
#include <graphics.h>
#include <conio.h>
#include <stdio.h>int main()
{initgraph(600, 600);int cnt = 0;int x = 300, y = 100, r = 50;int step = 10;while (true) {fillcircle(x, y, r);if (y >= 550) step = -10;if (y <= 50) step = 10;y += step;//实现加速运动的话,我们只需要每次加上一个变量即可Sleep(30);cleardevice();}_getch();closegraph();return 0;
}

4. 小球抛物线运动

小球抛物线运动_哔哩哔哩_bilibili

#include <iostream>
#include <graphics.h>
#include <conio.h>
#include <stdio.h>
#include <cmath>int main()
{double width = 900, height = 600;initgraph(width, height);double x = 300, y = 100, r = 10;double step = 5;/*(1)水平方向:s = v₀×t(2)竖直方向:h = (1 / 2)gt²*/double init_v = 10, t = 0, g = 5;while (true) {fillcircle(x, y, r);double s = init_v * t;double h = 0.5 * g *pow(t,2);x += s;y += h;t += 0.5;if (x >= width - 20 || y >= height - 20) break;Sleep(100);cleardevice();}_getch();closegraph();return 0;
}

5. 按空格小球弹起一次

按空格小球弹起_哔哩哔哩_bilibili

#include <iostream>
#include <graphics.h>
#include <conio.h>
#include <stdio.h>using std::cout;
using std::cin;
using std::endl;int main()
{int width = 900, height = 600;initgraph(width, height);int cir_x = 300, cir_y = 570, cir_r = 30;fillcircle(cir_x, cir_y, cir_r);int rec_left = 400, rec_top = 500, rec_right = 430, rec_bottom = height;fillrectangle(rec_left, rec_top, rec_right, rec_bottom);while (1) {if (_kbhit()) {//检测键盘是否有输入char input = _getch();if (input == ' ') {auto ball_jump = [=](int x, int y) mutable {int step = 0;int ty = y;//记录一下原来的位置,我们只跳起一次即可while (1) {if (y >= 570) step = -5;if (y <= 350) step = 5;y += step;fillcircle(x, y, cir_r);fillrectangle(rec_left, rec_top, rec_right, rec_bottom);if (y == ty) break;Sleep(20);cleardevice();}};ball_jump(cir_x, cir_y);}}}_getch();closegraph();return 0;
}

6. 小球躲避方块游戏演示

小球躲避方块游戏演示_哔哩哔哩_bilibili

#include <cmath>
#include <time.h>
#include <easyx.h>
#include <conio.h>
#include <graphics.h>
using namespace std;int main() {double width, height, gravity;double ball_x, ball_y, ball_vy, radius;double rect_left_x, rect_top_y, rect_width, rect_height, rect_vx;width = 600, height = 400, gravity = 0.6;initgraph(width, height);int score = 0;int isBallOnFloor = 1;radius = 20;ball_x = width / 4, ball_y = height - radius;ball_vy = 0;rect_height = 100, rect_width = 20;rect_left_x = width * 3 / 4, rect_top_y = height - radius;rect_vx = -3;while (1) {if (_kbhit()) {char input = _getch();if (input == ' '&& isBallOnFloor == 1) {//如果按下空格,且小球在地面就弹起,赋予向上初速度ball_vy = -17;isBallOnFloor = 0;}}ball_vy += gravity;ball_y += ball_vy; // 小球匀速上升运动if (ball_y >= height - radius ) {//如果出界ball_vy = 0;ball_y = height - radius;//调整位置,避免超出地图isBallOnFloor = 1;}rect_left_x += rect_vx;if (rect_left_x <= 0) {//如果方块到达了最左边rect_left_x = width;//出现在最右边score += 1;rect_height = rand() % int(height / 4) + height / 4;//随机方块高度,且最低height / 4rect_vx = rand() / float(RAND_MAX) * 4 - 7;//随机速度 且最低速度为 -3//rand () 产生 0 - RAND_MAX范围的数//short范围 -32768~32767 RAND_MAX = 0x7fff = 32767}//碰撞检测if ((rect_left_x <= ball_x + radius) && (rect_left_x + rect_width >= ball_x - radius)&& (height - rect_height <= ball_y + radius)) {Sleep(100);score = 0;}cleardevice();fillcircle(ball_x, ball_y, radius);fillrectangle(rect_left_x, height - rect_height, rect_left_x + rect_width, height);TCHAR s[20];_stprintf_s(s, _T("%d"), score);settextstyle(40,0,_T("宋体"));outtextxy(50, 30, s);Sleep(10);}closegraph();return 0;
}

7. 扇形绘制与颜色设置

#include <cmath>
#include <time.h>
#include <easyx.h>
#include <conio.h>
#include <graphics.h>
using namespace std;int main() {double width, height;width = 900, height = 600;initgraph(width, height);double radius = 100, x = 300, y = 300;// 画圆形的框int left = x - radius, top = y-radius, right = x + radius, bottom = y + radius;double PI = 3.14159265358;double stangle = 0, endangle = PI / 4;//1rad = 180 / π = 57.30°  // 起始弧度  和 终止弧度setbkcolor(WHITE);//先设置颜色、再绘图,才能得到对应颜色的绘制效果。//setbkcolor(RGB(255,255,255)); // 设置背景颜色为白色 RGB模式setlinecolor(RED);setfillcolor(GREEN);cleardevice();//清空背景 才能给背景上色circle(y, y, radius);solidpie(left, top, right, bottom, stangle,endangle);_getch();closegraph();return 0;
}

可以绘制一个彩色拼盘

  1. 旋转圆盘——动态视觉图

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-wJXlne14-1655694620232)(https://i.loli.net/2021/11/01/5sEYRMVNd9mwqXj.png)]

#include <cmath>
#include <time.h>
#include <easyx.h>
#include <conio.h>
#include <graphics.h>int main() {double width, height;width = 900, height = 600;initgraph(width, height);double radius = 100, x = 300, y = 300;// 画圆形的框int left = x - radius, top = y-radius, right = x + radius, bottom = y + radius;double PI = 3.14159265358;double stangle = PI / 30, endangle = PI / 20;//黑白的弧度 PI / 60double stangle_2 = 0, endangle_2 = PI / 30;//红青的弧度setbkcolor(WHITE);cleardevice();//清空才能上色// 起始弧度  和 终止弧度//画20组即可达成效果for(int i = 0; i < 20; i++){setfillcolor(GREEN);fillpie(left, top, right, bottom, stangle_2, endangle_2);stangle_2 += PI / 20;endangle_2 += PI / 20;setfillcolor(WHITE);fillpie(left, top, right, bottom, stangle, endangle);stangle += PI / 20;endangle += PI / 20;setfillcolor(RED);fillpie(left, top, right, bottom, stangle_2, endangle_2);stangle_2 += PI / 20;endangle_2 += PI / 20;setfillcolor(BLACK);fillpie(left, top, right, bottom, stangle, endangle);stangle += PI / 20;endangle += PI / 20;}_getch();closegraph();return 0;
}

还有同心圆

以及这个

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-8taPrO5t-1655694620234)(C:\Users\86187\AppData\Roaming\Typora\typora-user-images\image-20211101193325429.png)]

8. HSV颜色模型

第二个参数是模糊程度,第三个参数是灰暗程度

#include <cmath>
#include <time.h>
#include <easyx.h>
#include <conio.h>
#include <graphics.h>
#include <iostream>
#include <typeinfo>
using namespace std;int main() {double width, height;width = 800, height = 500;initgraph(width, height);setbkcolor(WHITE);cleardevice();double PI = 3.141592653589793;int x = 300, y = 300, r = 100;//圆弧的圆心int left = x - r, top = y - r, right = x + r, bottom = y + r;//外切矩形的左上角和右下角坐标int step = 10;COLORREF color;for (int i = 0; i < 360; i += step) {color = HSVtoRGB(i, 1, 1);setfillcolor(color);fillpie(left, top, right, bottom,i * PI / 180, (i + step) * PI / 180);}_getch();closegraph();return 0;
}

9. line 线条的绘制

  • 直线逼近曲线,xy对应坐标等距连接即可

#include <cmath>
#include <time.h>
#include <easyx.h>
#include <conio.h>
#include <graphics.h>int main() {double width, height;width = 800, height = 500;initgraph(width, height);setbkcolor(YELLOW);cleardevice();int len = 300;int col_x = 100, col_y = 10, col_endx = len + col_x, col_endy = col_y;//横线int row_x = col_x, row_y = col_y, row_endx = row_x, row_endy = len + row_y;//竖线setlinecolor(BLACK);int line_cnt = 10;for (int i = 1; i < line_cnt; i++) {line(col_x, col_y, col_endx, col_endy);col_x += 30;col_endy += 30;}_getch();closegraph();return 0;
}
  • 然后是11∗1111*1111∗11棋盘的绘制

#include <cmath>
#include <time.h>
#include <easyx.h>
#include <conio.h>
#include <graphics.h>int main() {double width, height;width = 800, height = 500;initgraph(width, height);setbkcolor(YELLOW);cleardevice();int len = 300;int col_x = 100, col_y = 10, col_endx = len + col_x, col_endy = col_y;//竖线int row_x = col_x, row_y = col_y, row_endx = row_x, row_endy = len + row_y;//横线setlinecolor(BLACK);int line_cnt = 10;for (int i = 0; i <= line_cnt; i++) {line(col_x, col_y, col_endx, col_endy);line(row_x, row_y, row_endx, row_endy);col_y += 30;col_endy += 30;row_x += 30;row_endx += 30;}_getch();closegraph();return 0;
}

Easyx 学习笔记相关推荐

  1. EasyX学习笔记(二、黑客帝国数据流)

    EasyX学习笔记(二.黑客帝国数据流) 思路说明 main函数 startup函数 show函数 updatewithoutinput函数 结构 代码 思路说明 main函数 1.main函数中应包 ...

  2. PyTorch 学习笔记(六):PyTorch hook 和关于 PyTorch backward 过程的理解 call

    您的位置 首页 PyTorch 学习笔记系列 PyTorch 学习笔记(六):PyTorch hook 和关于 PyTorch backward 过程的理解 发布: 2017年8月4日 7,195阅读 ...

  3. 容器云原生DevOps学习笔记——第三期:从零搭建CI/CD系统标准化交付流程

    暑期实习期间,所在的技术中台-效能研发团队规划设计并结合公司开源协同实现符合DevOps理念的研发工具平台,实现研发过程自动化.标准化: 实习期间对DevOps的理解一直懵懵懂懂,最近观看了阿里专家带 ...

  4. 容器云原生DevOps学习笔记——第二期:如何快速高质量的应用容器化迁移

    暑期实习期间,所在的技术中台-效能研发团队规划设计并结合公司开源协同实现符合DevOps理念的研发工具平台,实现研发过程自动化.标准化: 实习期间对DevOps的理解一直懵懵懂懂,最近观看了阿里专家带 ...

  5. 2020年Yann Lecun深度学习笔记(下)

    2020年Yann Lecun深度学习笔记(下)

  6. 2020年Yann Lecun深度学习笔记(上)

    2020年Yann Lecun深度学习笔记(上)

  7. 知识图谱学习笔记(1)

    知识图谱学习笔记第一部分,包含RDF介绍,以及Jena RDF API使用 知识图谱的基石:RDF RDF(Resource Description Framework),即资源描述框架,其本质是一个 ...

  8. 计算机基础知识第十讲,计算机文化基础(第十讲)学习笔记

    计算机文化基础(第十讲)学习笔记 采样和量化PictureElement Pixel(像素)(链接: 采样的实质就是要用多少点(这个点我们叫像素)来描述一张图像,比如,一幅420x570的图像,就表示 ...

  9. Go 学习推荐 —(Go by example 中文版、Go 构建 Web 应用、Go 学习笔记、Golang常见错误、Go 语言四十二章经、Go 语言高级编程)

    Go by example 中文版 Go 构建 Web 应用 Go 学习笔记:无痕 Go 标准库中文文档 Golang开发新手常犯的50个错误 50 Shades of Go: Traps, Gotc ...

最新文章

  1. 微软联合创始人都看好,这项技术有什么过人之处?
  2. 关于Datastage资料库的一点小发现
  3. mysql主从复制监控shell脚本
  4. SAP Cloud for Customer的后台作业
  5. 吴恩达斯坦福实验室发布MRNet数据集,包含1千多张标注膝关节核磁共振成像
  6. [转]何为C10K问题
  7. luogu P3193 [HNOI2008]GT考试
  8. 2.shiro+jdbc+idea+maven数据库
  9. 【BDTC 2018】PingCAP申砾:做一个真正通用的数据库产品
  10. n++和++n的区别
  11. 数字化转型:信息系统的生命周期(一)
  12. java接口推送_推送API
  13. sklearn.svm.SVC的方法decision_function_shape:ovr 或者 ovo
  14. 测试服务器网站并发,Nginx服务器10000 并发 优化测试(ab测试工具)
  15. 20145204张亚军《网络对抗技术》恶意代码分析
  16. 20141115 【 Arduino - LM35 - 4位八段数码管 】 数码管显示温度
  17. 基于stm32单片机的四种波形发生器正弦波、方波、三角波、锯齿波
  18. 机器学习中的聚类算法
  19. 【Mac/ios】ios开发,添加测试手机UDID方法
  20. 计算机图形学作业( 七):利用 OpenGL 绘制 Bezier 贝塞尔曲线

热门文章

  1. Coldfusion 2016出现The error occurred in scheduletasks.cfm: line 188
  2. 计算机专业申请截止时间,通知 2021年曼彻斯特大学计算机学院公布了申请截止时间及申请条件!...
  3. 计算机网络实验二交换机配置Cisco,计算机网络实验1 — Cisco交换机的配置
  4. 写在Nokia和微软结盟之后
  5. (75)游戏服务器开发的基本体系与服务器端开发的一些建议
  6. linux /usr/bin 和/usr/local/bin 区别
  7. The local variable fruit may not have been initialized 错误
  8. 执行未来计划每日打卡
  9. 【qt】windows下本地文件的标准url格式
  10. 中国股民掉进罗杰斯们的陷阱(摘录)