跳动的爱心

跳动的心形图案,通过字符打印和延时效果模拟跳动,心形在两种大小间交替跳动。

通过数学公式生成心形曲线

#include <stdio.h>

#include <windows.h> // Windows 系统头文件(用于延时和清屏)

void printHeart(int size, int beat) {

for (int y = size; y >= -size; y--) {

for (int x = -size; x <= size; x++) {

// 心形数学公式:(x² + y² - 1)³ - x²y³ ≤ 0(调整参数模拟跳动)

float fx = (x * 0.4f * beat) * (x * 0.4f * beat) + (y * 0.4f) * (y * 0.4f) - 1;

if (fx * fx * fx - (x * 0.4f * beat) * (y * 0.4f) * (y * 0.4f) * (y * 0.4f) <= 0) {

printf("@");

} else {

printf(" "); // 空格填充

}

}

printf("\n");

}

}

int main() {

int beat = 1; // 跳动幅度(1-2)

while (1) {

system("cls"); // 清屏(Linux/macOS 需改为 "clear")

printHeart(15, beat); // 绘制心形(尺寸15,幅度beat)

Sleep(100); // 延时100ms

beat = (beat == 1) ? 2 : 1; // 切换跳动幅度

}

return 0;

}

相关推荐
祈安_3 天前
C语言内存函数
c语言·后端
norlan_jame5 天前
C-PHY与D-PHY差异
c语言·开发语言
czy87874755 天前
除了结构体之外,C语言中还有哪些其他方式可以模拟C++的面向对象编程特性
c语言
m0_531237175 天前
C语言-数组练习进阶
c语言·开发语言·算法
Z9fish5 天前
sse哈工大C语言编程练习23
c语言·数据结构·算法
代码无bug抓狂人5 天前
C语言之单词方阵——深搜(很好的深搜例题)
c语言·开发语言·算法·深度优先
CodeJourney_J5 天前
从“Hello World“ 开始 C++
c语言·c++·学习
枫叶丹45 天前
【Qt开发】Qt界面优化(七)-> Qt样式表(QSS) 样式属性
c语言·开发语言·c++·qt
with-the-flow5 天前
从数学底层的底层原理来讲 random 的函数是怎么实现的
c语言·python·算法
Sunsets_Red5 天前
P8277 [USACO22OPEN] Up Down Subsequence P 题解
c语言·c++·算法·c#·学习方法·洛谷·信息学竞赛