java跳动爱心的代码
时间: 2023-11-25 10:52:16 浏览: 139
java爱心代码跳动.md
以下是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) {
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 = Math.round(x * 100.0) / 100.0;
y = Math.round(y * 100.0) / 100.0;
s[(int) (15 - y)][(int) (40 + x)] = '*';
}
for (int i = 0; i < 30; i++) {
for (int j = 0; j < 80; j++) {
System.out.print(s[i][j]);
}
System.out.println();
}
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
```
阅读全文