跳动爱心代码java
时间: 2023-11-25 14:52:22 浏览: 97
以下是Java实现跳动爱心的代码:
```java
public class Heart {
public static void main(String[] args) {
double x, y, size;
char[][] s = new char[30][80];
while (true) {
for (int i = 0; i < 30; i++) {
for (int j = 0; j < 80; j++) {
s[i][j] = ' ';
}
}
for (double i = 0; i < 2 * Math.PI; i += 0.01) {
for (double j = 0; j < 2 * Math.PI; j += 0.05) {
x = 16 * Math.pow(Math.sin(j), 3);
y = 13 * Math.cos(j) - 5 * Math.cos(2 * j) - 2 * Math.cos(3 * j) - Math.cos(4 * j);
size = Math.sin(i);
int x1 = (int) Math.floor(x * size + 40);
int y1 = (int) Math.floor(y * size + 15);
if (x1 >= 0 && x1 < 80 && y1 >= 0 && y1 < 30) {
s[y1][x1] = '*';
}
}
}
for (int i = 0; i < 30; i++) {
System.out.println(s[i]);
}
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
```
阅读全文