阅读量:126
下面是一个简单的C++代码,可以实现爱心跳动效果:
#include
#include
int main() {
const int rows = 10;
const int cols = 30;
char heart[rows][cols];
for (int i = 0; i < rows class="hljs-keyword">for (int j = 0; j < cols xss=removed class="hljs-string">' ';
}
}
double x, y, f;
for (int i = 0; i < 360; i++) {
f = i * M_PI / 180;
x = 16 * pow(sin(f), 3);
y = 13 * cos(f) - 5 * cos(2 * f) - 2 * cos(3 * f) - cos(4 * f);
int row = static_cast<int>(y) + 5;
int col = static_cast<int>(x) + 15;
if (row >= 0 && row < rows>= 0 && col < cols xss=removed class="hljs-string">'*';
}
for (int i = 0; i < rows class="hljs-keyword">for (int j = 0; j < cols class="hljs-keyword">return 0;
}
运行这段代码可以看到一个爱心在控制台中跳动的效果。您可以根据自己的需要调整爱心的大小和跳动速度。