《点燃我,温暖你》理工男神李峋同款C语言版本爱心

近期很火的《 点燃我,温暖你》很火,里面的 _爱心代码_也很惊艳,但是程序员看了觉得尬的扣脚,

网上也有他其他的语言爱心源码,但都不是C语言的,用语言描述一下,就是好多爱心,然后从内到外,从小到大的显示。今天就给大家分享: _爱心代码,_边看边用!

2.实现

C语言程序的编写就像同将一头大象放到冰箱里。

1、打开冰箱

2、放入大象

3、关上冰箱

首先就是计算坐标,更新坐标,绘制爱心三步。重复调用,就可以实现。里面的具体细节,可以查看代码。

3.运行效果

《点燃我,温暖你》理工男神李峋同款C语言版本爱心

4.源码


///
// 程序名称:《点燃我,温暖你》爱心程序
// 编译环境:Mictosoft Visual Studio 2013,+EasyX_20200315(beta)
// 作  者:爱编程的胡桃
// 源码获取加q群:724050348   想学习更多项目、和同行交流学习都可以进来 ~
//

#include<graphics.h>
#include<conio.h>
#include<time.h>
#include<math.h>
#include<sys timeb.h>

struct MyLove
{
  int NUMS;  //  &#x7F16;&#x53F7;
  double m;
  double n;
  double size;
  bool Is_show;
  int x;
  int y;
};

MyLove mylove[400];
int CenterX = 320;
int CenterY = 180;
double Size = 60;
void initdata();  // &#x521D;&#x59CB;&#x5316;&#x6570;&#x636E;
void updata();    // &#x66F4;&#x65B0;
void movedata();  // &#x5E73;&#x79FB;
void showdata();  // &#x663E;&#x793A;
int* GetRand(int* buf, int count, int range);  // &#x968F;&#x673A;&#x6570;&#x7684;&#x751F;&#x6210;
void heart(int x0, int y0, int size, COLORREF C);
void HpSleep(int ms);

int main()
{
  initgraph(640, 480);
  initdata();
  BeginBatchDraw();
  while (true)
  {
    updata();
    showdata();
    HpSleep(30);    // &#x6539;&#x4E3A;&#x7CBE;&#x786E;&#x5EF6;&#x65F6;
    FlushBatchDraw();
    cleardevice();
  }
  EndBatchDraw();
  _getch();
  return 0;
}

void updata()
{
  int* buf = (int*)malloc(sizeof(int)* 20);
  buf = GetRand(buf, 20, (int)(2 * Size / 0.01));
  movedata();
  for (int i = 0; i < 20; i++)
  {
    mylove[i].m = buf[i] * 0.01;
    mylove[i].n = (((sin(buf[(int)i] * 0.01) * sqrt(fabs(cos(buf[(int)i] * 0.01)))) / (sin(buf[(int)i] * 0.01) + 1.4142)) - 2 * sin(buf[(int)i] * 0.01) + 2);
    mylove[i].size = Size;
    mylove[i].NUMS = i / 20;
    mylove[i].Is_show = true;
    mylove[i].x = (int)(-Size *mylove[i].n * cos(mylove[i].m) + CenterX);
    mylove[i].y = (int)(-Size *mylove[i].n * sin(mylove[i].m) + CenterY - mylove[i].size);
  }
  for (int i = 20; i < 400; i++)
  {
    mylove[i].size = mylove[i].size + 1;
    if (mylove[i].size>80)
    {
      mylove[i].size = 80;
    }
    mylove[i].NUMS = i / 20;
    mylove[i].x = (int)(-mylove[i].size *mylove[i].n * cos(mylove[i].m) + CenterX);
    mylove[i].y = (int)(-mylove[i].size *mylove[i].n * sin(mylove[i].m) + CenterY - mylove[i].size);
  }
}

void movedata()
{
  for (int i = 399; i > 19; i--)
  {
    mylove[i] = mylove[i - 20];
  }
}

void showdata()
{
  settextcolor(RED);
  wchar_t c = 0x59;    // 0x28 &#x662F;&#x7535;&#x8BDD;&#x673A;&#x5728; Wingdings &#x5B57;&#x4F53;&#x4E2D;&#x7684;&#x5BF9;&#x5E94;&#x7F16;&#x7801;
  for (int i = 0; i < 400; i++)
  {
    settextstyle(mylove[i].NUMS + 10, 0, "Webdings");
    setbkmode(TRANSPARENT);
    outtextxy(mylove[i].x + 20, mylove[i].y + 20, c);
  }
}

int* GetRand(int* buf, int count, int range)
{
  struct timeb timeSeed;
  ftime(&timeSeed);
  srand(timeSeed.time * 1000 + timeSeed.millitm);  // milli time
  for (int i = 0; i < count; i++)
  {
    int randTmp = rand() % range;
    for (int j = 0; j < i; j++)
    {
      if (buf[j] == randTmp)
      {
        break;//&#x68C0;&#x67E5;&#x91CD;&#x590D;&#x3002;
      }
    }
    buf[i] = randTmp;
  }
  return buf;
}

void initdata()
{
  for (int i = 0; i < 400; i++)
  {
    mylove[i].NUMS = 0;
    mylove[i].m = 0;
    mylove[i].n = 0;
    mylove[i].size = 0;
    mylove[i].Is_show = false;
    mylove[i].x = 0;
    mylove[i].y = 0;
  }
}

// &#x7CBE;&#x786E;&#x5EF6;&#x65F6;&#x51FD;&#x6570;(&#x53EF;&#x4EE5;&#x7CBE;&#x786E;&#x5230; 1ms&#xFF0C;&#x7CBE;&#x5EA6; &#xB1;1ms)
// by yangw80<yw80@qq.com>, 2011-5-4
void HpSleep(int ms)
{
  static clock_t oldclock = clock();    // &#x9759;&#x6001;&#x53D8;&#x91CF;&#xFF0C;&#x8BB0;&#x5F55;&#x4E0A;&#x4E00;&#x6B21; tick
  oldclock += ms * CLOCKS_PER_SEC / 1000;  // &#x66F4;&#x65B0; tick
  if (clock() > oldclock)          // &#x5982;&#x679C;&#x5DF2;&#x7ECF;&#x8D85;&#x65F6;&#xFF0C;&#x65E0;&#x9700;&#x5EF6;&#x65F6;
    oldclock = clock();
  else
  while (clock() < oldclock)      // &#x5EF6;&#x65F6;
    Sleep(1);            // &#x91CA;&#x653E; CPU &#x63A7;&#x5236;&#x6743;&#xFF0C;&#x964D;&#x4F4E; CPU &#x5360;&#x7528;&#x7387;&#xFF0C;&#x7CBE;&#x5EA6; 10~16ms
  //      Sleep(0);            // &#x66F4;&#x9AD8;&#x7CBE;&#x5EA6;&#x3001;&#x66F4;&#x9AD8; CPU &#x5360;&#x7528;&#x7387;&#xFF0C;&#x7CBE;&#x5EA6; 1ms
}</yw80@qq.com></sys></math.h></time.h></conio.h></graphics.h>

Original: https://blog.csdn.net/yx5666/article/details/127788428
Author: 编程小鱼六六六
Title: 《点燃我,温暖你》理工男神李峋同款C语言版本爱心



相关阅读

Title: Python入门初学二、Python下载/安装/环境配置/模块安装/解决pip下载模块慢

兄弟们,既然要学python,那么这些软件是需要先安装一下的。

一、Python 下载
Python是运行的环境,必不可少,如果你是Linux系统的话,不用安装,自带了Python。

首先我们打开浏览器搜索Python,选择这个后面带官方标识的,点击进去。

《点燃我,温暖你》理工男神李峋同款C语言版本爱心

选择Python,鼠标移动到 Downloads(下载) 上面,选择右边的3.10.0版本,点击即可下载。

《点燃我,温暖你》理工男神李峋同款C语言版本爱心
如果你要下载其它版本,选择 Downloads(下载) 点击 All releases(所有版本)
《点燃我,温暖你》理工男神李峋同款C语言版本爱心
下拉,看到这个地方,选择你想要的版本,不要推荐最新的,最新的不稳定。
[En]

Pull down, see this place, choose the version you want, do not recommend the latest, the latest is unstable.

《点燃我,温暖你》理工男神李峋同款C语言版本爱心
我们随便打开一个版本,往下翻到files,选择最下面的Windows installer ,你的电脑是多少位的,就下载多少位的。
《点燃我,温暖你》理工男神李峋同款C语言版本爱心
二、Python安装
然后,我们开始安装,并双击打开Run安装包。
[En]

Then we start the installation and double-click to open the run installation package.

《点燃我,温暖你》理工男神李峋同款C语言版本爱心
install now是默认安装路径,简单省事。
如果不想放在C盘,就选择第二个自定义安装。
add Python 3.10 to PATH 点上对钩,它自动配置环境变量,如果没有选择,安装好后还得重新配置环境变量。

选择自定义安装

《点燃我,温暖你》理工男神李峋同款C语言版本爱心
全部选上,然后点next(下一步)
《点燃我,温暖你》理工男神李峋同款C语言版本爱心

选择browse(浏览),选择安装目录,然后点install(安装)

《点燃我,温暖你》理工男神李峋同款C语言版本爱心
静静等待即可
《点燃我,温暖你》理工男神李峋同款C语言版本爱心
安装好后可以看到这里有这 online tutorial ,是一个帮助文档,documentation 是一个在线手册,都是英文文档,英文好的话,可以看看,不看也没事。

然后点close关闭就好了

《点燃我,温暖你》理工男神李峋同款C语言版本爱心

三、配置环境变量

Python安装的话,基本就结束了,然后按 win+r 打开搜索框,输入cmd 点击确定。

《点燃我,温暖你》理工男神李峋同款C语言版本爱心

在弹出的命令提示符页面输入Python,这样的话就是安装成功了。

《点燃我,温暖你》理工男神李峋同款C语言版本爱心
如果你没有把Python配置环境变量就会是这样,Python不是内部或外部命令。《点燃我,温暖你》理工男神李峋同款C语言版本爱心
但是,如果您直接在安装目录中打开它,则可以打开它,但如果我们配置环境变量,则它可以在任何位置打开。如果系统加载,则首先从系统变量加载,包括我们的计算机系统STARTUP,它也在系统变量中。
[En]

However, if you open it directly in the installation directory, it can be opened, but if we configure the environment variable, it can be opened wherever it is. If the system loads, it is first loaded from the system variable, including our computer system startup, which is also in the system variable.

让我们讨论一下如何配置环境变量。

[En]

Let’s talk about how to configure environment variables.

在我的电脑上单击鼠标右键并选择属性。

[En]

Right-click on my computer and select Properties.

《点燃我,温暖你》理工男神李峋同款C语言版本爱心
点击高级系统设置
《点燃我,温暖你》理工男神李峋同款C语言版本爱心
点击环境变量
《点燃我,温暖你》理工男神李峋同款C语言版本爱心
选择path
《点燃我,温暖你》理工男神李峋同款C语言版本爱心
在编辑环境变量中单击新建
[En]

Click New in the edit environment variable

《点燃我,温暖你》理工男神李峋同款C语言版本爱心
然后复制你的Python安装路径
《点燃我,温暖你》理工男神李峋同款C语言版本爱心
粘贴到新框中,单击确定,然后在上一个打开的框中单击确定。
[En]

Paste into the new box, click OK, and click OK on the previous opening.

《点燃我,温暖你》理工男神李峋同款C语言版本爱心
然后重启cmd,再次输入Python就可以啦。
《点燃我,温暖你》理工男神李峋同款C语言版本爱心

四、pip下载模块慢

安装模块

键盘按【win+r】打开搜索框,输入【cmd】按回车,在弹出的命令提示符窗口输入【pip install (你想要安装的模块名)】,比如我安装【pygame】,输入【pip install pygame】,然后按回车等待即可。

《点燃我,温暖你》理工男神李峋同款C语言版本爱心
但在这种情况下,速度很慢,它提示我大约需要三分钟,这是因为它是从外部服务器下载的,所以它超级慢,有时模块稍大一些,下载超时。你能忍受吗?
[En]

But in this case, the speed is very slow, it prompts me that it will take about three minutes, this is because it is downloaded from a foreign server, so it is super slow, sometimes the module is a little larger, and the download times out. Can you stand it?

那么我们就可以用国内的镜像源来代替它下载了。

[En]

Then it would be good for us to replace it with a domestic mirror source to download.

两种方式

第一种临时配置
您可以在安装过程中添加并直接安装镜像源,例如

[En]

You can add the mirror source and install it directly during installation, such as

这是清华大学镜像源 :https://pypi.tuna.tsinghua.edu.cn/simple/
那我们直接输入

pip install pygame -i https://pypi.tuna.tsinghua.edu.cn/simple/

速度超级快。

第二种永久配置
Windows环境下直接在命令提示框输入

pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

然后再去安装模块的时候,咱们直接使用原来的方式,比如Scapy为例,输入 【pip install Scapy】
安装时自动施加镜像源,速度超快。

[En]

When installing, it automatically applies the mirror source, and the speed is super fast.

《点燃我,温暖你》理工男神李峋同款C语言版本爱心
然后卸载模块的话,把【install】替换为【uninstall】即可,以pygame模块为例,输入【pip uninstall pygame】按回车等待即可。
《点燃我,温暖你》理工男神李峋同款C语言版本爱心

兄弟们,你们的学习有没有不及格?记得要喜欢这个收藏~

[En]

Brothers, have you failed your studies? Remember to like the collection ~

《点燃我,温暖你》理工男神李峋同款C语言版本爱心

Original: https://blog.csdn.net/ooowwq/article/details/121184537
Author: 轻松学Python
Title: Python入门初学二、Python下载/安装/环境配置/模块安装/解决pip下载模块慢

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/349986/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

最近整理资源【免费获取】:   👉 程序员最新必读书单  | 👏 互联网各方向面试题下载 | ✌️计算机核心资源汇总