1 Star 0 Fork 0

PZ闪电/Heart

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Heart.java 2.96 KB
一键复制 编辑 原始数据 按行查看 历史
潘震 提交于 2023-12-08 04:30 +08:00 . first
package com.ruoyi.web.controller.system;
import java.awt.*;
import javax.swing.JFrame;
public class Heart extends JFrame {
//定义窗口大小
private static final int WIDTH = 1000;
private static final int HEIGHT = 1000;
//获取屏幕大小
private static final int WINDOW_WIDTH = Toolkit.getDefaultToolkit().getScreenSize().width;
private static final int WINDOW_HEIGHT = Toolkit.getDefaultToolkit().getScreenSize().height;
public Heart() {
//设置窗口标题
super("Heart");
//设置背景色
this.setBackground(Color.BLACK);
//设置窗口位置
this.setLocation((WINDOW_WIDTH - WIDTH) / 2, (WINDOW_HEIGHT - HEIGHT) / 2);
//设置窗口大小
this.setSize(WIDTH, HEIGHT);
//设置窗口布局
this.setLayout(getLayout());
//设置窗口可见
this.setVisible(true);
//设置窗口的默认关闭方式
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
/**
* 图形函数
*/
public void paint(Graphics g) {
//横纵坐标及半径
double x;
double y;
//绘制图形
double z = 0.0;
double size;
int jj = 0;
while (true) {
Image image = this.createImage(WIDTH, HEIGHT);
Graphics pic = image.getGraphics();
size = jj % 2 == 0 ? 14.5 : 15;
for (int ii = 30; ii > 0; ii--) {
Color color = new Color(255, 0, (int) (20 * Math.random()) + 220);
for (int i = 1; i < 400; i++) {
int px = (int) (Math.random() * 10);
int py = (int) (Math.random() * 10);
x = 16 * (Math.sin(z) * Math.sin(z) * Math.sin(z)) * (size) + Math.pow((-1), px) * Math.random()
* ii * Math.sqrt(ii) + (double) WIDTH / 2;
y = -(13 * Math.cos(z) - 5 * Math.cos(2 * z) - 2 * Math.cos(3 * z) - Math.cos(4 * z)) * (size)
+ Math.pow((-1), py) * Math.random() * ii * Math.sqrt(ii) + (double) (HEIGHT) / 3;
z += (Math.PI / 2.0) / 80;
pic.setColor(color);
pic.fillOval((int) x, (int) y, 2, 2);
}
if (ii < 3) {
//设置字体
pic.setFont(new Font("楷体", Font.BOLD, 40));
pic.setColor(Color.pink);
//绘制字符串
// pic.drawString("I Love You", WIDTH / 2 - 100, 350);
g.drawImage(image, 0, 0, this);
}
}
jj++;
if (jj > 100) {
break;
}
try {
Thread.sleep(270);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
/**
* Main函数启动
*/
public static void main(String[] args) {
new Heart();
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/pz_lightning/heart.git
git@gitee.com:pz_lightning/heart.git
pz_lightning
heart
Heart
master

搜索帮助