跳动的爱心

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

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

#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;

}

相关推荐
aaaameliaaa2 小时前
字符函数和字符串函数
c语言·笔记·算法
夜月yeyue2 小时前
AUTOSAR CP 从上电到 Runnable
c语言·网络·tcp/ip·车载系统
白白白小纯4 小时前
算法篇—反转链表
c语言·数据结构·算法·leetcode
小羊先生car4 小时前
RTOS-F429-HAL-绝对延时和相对延时(2026/7/31)
c语言·rtos
caishenzhibiao8 小时前
期货先行者主图 同花顺期货通指标
java·c语言·c#
NoteStream11 小时前
【c语言基础】C语言常见概念
c语言·开发语言·编辑器
caishenzhibiao11 小时前
先行者副图 同花顺期货通指标
java·c语言·c#
回眸不遇12 小时前
将 Docker虚拟磁盘文件ext.vhdx迁移出C盘 ,更换到D盘
c语言·docker·容器
冻柠檬飞冰走茶12 小时前
PTA基础编程题目集 7-27 冒泡法排序(C语言实现)
c语言·开发语言·数据结构·算法
wuyk55512 小时前
77.嵌入式 C 语言中 enum 枚举的工程化实践:告别魔法数字,提升代码可维护性
c语言·开发语言·stm32·单片机·嵌入式硬件