用C语言实现跳动爱心
时间: 2024-03-09 17:41:09 浏览: 107
以下是用C语言实现跳动爱心的代码:
```
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <windows.h>
int main()
{
float x, y, z, f;
int i, j, k, r;
int a[80][80] = {0};
char b[80][80] = {' '};
for (k = 0; k < 100; k++)
{
for (i = 0; i < 80; i++)
{
for (j = 0; j < 80; j++)
{
x = (j - 40) * 0.04f;
y = (i - 40) * 0.1f;
z = x * x + y * y - 1;
f = z * z * z - x * x * y * y * y;
if (f <= 0.0f)
{
a[i][j] = 1;
}
else
{
a[i][j] = 0;
}
}
}
system("cls");
for (i = 0; i < 80; i++)
{
for (j = 0; j < 80; j++)
{
if (a[i][j] == 1)
{
b[i][j] = '*';
}
else
{
b[i][j] = ' ';
}
}
}
for (i = 0; i < 80; i++)
{
for (j = 0; j < 80; j++)
{
printf("%c", b[i][j]);
}
printf("\n");
}
Sleep(100);
for (i = 0; i < 80; i++)
{
for (j = 0; j < 80; j++)
{
if (a[i][j] == 1)
{
r = rand() % 7;
if (r == 0)
{
b[i][j] = '\\';
}
else if (r == 1)
{
b[i][j] = '|';
}
else if (r == 2)
{
b[i][j] = '/';
}
else if (r == 3)
{
b[i][j] = '-';
}
else
{
b[i][j] = '*';
}
}
}
}
}
return 0;
}
```
阅读全文