用java写一个爱心跳动代码
时间: 2023-11-21 13:57:23 浏览: 99
java代码实现动态爱心代码示例
以下是Java实现爱心跳动的代码:
```java
public class HeartBeat {
public static void main(String[] args) {
double x, y, size;
char[][] heart = new char[30][60];
for (int i = 0; i < 30; i++) {
for (int j = 0; j < 60; j++) {
heart[i][j] = ' ';
}
}
for (double i = 0; i < 2 * Math.PI; i += 0.01) {
x = 16 * Math.pow(Math.sin(i), 3);
y = 13 * Math.cos(i) - 5 * Math.cos(2 * i) - 2 * Math.cos(3 * i) - Math.cos(4 * i);
x += 30;
y += 15;
size = Math.sin(i) * 10 + 10;
heart[(int) y][(int) x] = '*';
}
for (int i = 0; i < 30; i++) {
for (int j = 0; j < 60; j++) {
System.out.print(heart[i][j]);
}
System.out.println();
}
}
}
```
阅读全文