生日快乐的网页版,代码以及运行结果图(内置Java HTML代码) 代码1 Java生日祝福 倒计时import java.util.concurrent.TimeUnit; public class BirthdayHappy { public static void main(String[] args) { System.out.println(Happy Birthday “姓名”! ); // 倒计时 System.out.println(\nCounting down to the fireworks...); for (int i 10; i 0; i--) { System.out.println(i); try { TimeUnit.SECONDS.sleep(1); } catch (InterruptedException e) { e.printStackTrace(); } } System.out.println(Happy Birthday “姓名”! ); // 烟花 System.out.println(\nFireworks display ); // 生成蛋糕 System.out.println(\nHere is your birthday cake! ); } }代码2 Java烟花绽放import javax.swing.*; import java.awt.*; import java.util.ArrayList; import java.util.Random; public class Happy extends JPanel { private final ArrayListParticle particles new ArrayList(); private final Random random new Random(); private final String message; public Happy(String message) { this.message message; setBackground(Color.BLACK); new Timer(16, e - { update(); repaint(); }).start(); } private void update() { // 更新粒子状态 for (int i 0; i particles.size(); i) { Particle p particles.get(i); p.update(); if (p.life 0) { particles.remove(i); i--; } } // 添加新粒子频率提高数量增加 if (random.nextInt(5) 0) { // 频率提高原为10 double centerX random.nextDouble() * getWidth(); double centerY random.nextDouble() * getHeight() / 2; // 粒子数量增加到200原为100 for (int i 0; i 200; i) { double angle random.nextDouble() * 2 * Math.PI; double speed random.nextDouble() * 4 2; // 速度稍快 double vx speed * Math.cos(angle); double vy speed * Math.sin(angle); Color color new Color(random.nextInt(255), random.nextInt(255), random.nextInt(255)); // 生命周期延长原为5050 particles.add(new Particle(centerX, centerY, vx, vy, color, 100 random.nextInt(50))); } } } Override protected void paintComponent(Graphics g) { super.paintComponent(g); // 绘制粒子 for (Particle p : particles) { p.draw(g); } // 绘制文案 g.setColor(Color.PINK); g.setFont(new Font(宋体, Font.BOLD, 74)); g.drawString(message, getWidth() / 3, getHeight() - 450); } public static void main(String[] args) { JFrame frame new JFrame(动态烟花); //页面显示字体内容 String customMessage 姓名 生日快乐!; Happy fireworks new Happy(customMessage); frame.add(fireworks); frame.setSize(1600, 900); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } } class Particle { public double x, y; public double vx, vy; public Color color; public int life; public Particle(double x, double y, double vx, double vy, Color color, int life) { this.x x; this.y y; this.vx vx; this.vy vy; this.color color; this.life life; } public void update() { x vx; y vy; life--; vy 0.03; // 减小重力影响 } public void draw(Graphics g) { if (life 0) { g.setColor(color); // 增大粒子尺寸原为5x5 int size 2 (int)(life * 0.1); // 动态大小8-13像素 g.fillOval((int)x, (int)y, size, size); } } }代码3 HTML动态绘制蛋糕加祝福import turtle as t import math as m import random as r def drawX(a, i): angle m.radians(i) return a * m.cos(angle) def drawY(b, i): angle m.radians(i) return b * m.sin(angle) # 设置背景颜色窗口位置以及大小 t.bgcolor(#d3dae8) t.setup(width900, height600, startx0, starty0) t.title(姓名祝你生日快乐) t.speed(2) t.penup() t.goto(150, 0) t.pendown() # 1 t.pencolor(white) t.begin_fill() for i in range(360): x drawX(150, i) y drawY(60, i) t.goto(x, y) t.fillcolor(#fef5f7) t.end_fill() # 2 t.begin_fill() for i in range(180): x drawX(150, -i) y drawY(70, -i) t.goto(x, y) for i in range(180, 360): x drawX(150, i) y drawY(60, i) t.goto(x, y) t.fillcolor(#f2d7dd) t.end_fill() # 3 t.pu() t.goto(120, 0) t.pd() t.begin_fill() for i in range(360): x drawX(120, i) y drawY(48, i) t.goto(x, y) t.fillcolor(#cbd9f9) t.end_fill() # 4 t.begin_fill() t.pencolor(#fee48c) for i in range(540): x drawX(120, i) y drawY(48, i) 70 t.goto(x, y) t.goto(-120, 0) t.fillcolor(#cbd9f9) t.end_fill() # 5 t.pu() t.goto(120, 70) t.pd() t.pencolor(#fff0f3) t.begin_fill() for i in range(360): x drawX(120, i) y drawY(48, i) 70 t.goto(x, y) t.fillcolor(#fff0f3) t.end_fill() # 6 t.pu() t.goto(110, 70) t.pd() t.pencolor(#fff9fb) t.begin_fill() for i in range(360): x drawX(110, i) y drawY(44, i) 70 t.goto(x, y) t.fillcolor(#fff9fb) t.end_fill() # 7 t.pu() t.goto(120, 0) t.pd() t.begin_fill() t.pencolor(#ffa79d) for i in range(180): x drawX(120, -i) y drawY(48, -i) 10 t.goto(x, y) t.goto(-120, 0) for i in range(180, 360): x drawX(120, i) y drawY(48, i) t.goto(x, y) t.fillcolor(#ffa79d) t.end_fill() # 8 t.pu() t.goto(120, 70) t.pd() t.begin_fill() t.pensize(4) t.pencolor(#fff0f3) for i in range(1800): x drawX(120, 0.1 * i) y drawY(-18, i) 10 t.goto(x, y) t.goto(-120, 70) t.pensize(1) for i in range(180, 360): x drawX(120, i) y drawY(48, i) 70 t.goto(x, y) t.fillcolor(#fff0f3) t.end_fill() # 9 t.pu() t.goto(80, 70) t.pd() t.begin_fill() t.pencolor(#6f3732) t.goto(80, 120) for i in range(180): x drawX(80, i) y drawY(32, i) 120 t.goto(x, y) t.goto(-80, 70) for i in range(180, 360): x drawX(80, i) y drawY(32, i) 70 t.goto(x, y) t.fillcolor(#6f3732) t.end_fill() # 10 t.pu() t.goto(80, 120) t.pd() t.pencolor(#ffaaa0) t.begin_fill() for i in range(360): x drawX(80, i) y drawY(32, i) 120 t.goto(x, y) t.fillcolor(#ffaaa0) t.end_fill() # 11 t.pu() t.goto(70, 120) t.pd() t.pencolor(#ffc3be) t.begin_fill() for i in range(360): x drawX(70, i) y drawY(28, i) 120 t.goto(x, y) t.fillcolor(#ffc3be) t.end_fill() # 12 t.pu() t.goto(80, 120) t.pd() t.begin_fill() t.pensize(3) t.pencolor(#ffaaa0) for i in range(1800): x drawX(80, 0.1 * i) y drawY(-12, i) 80 t.goto(x, y) t.goto(-80, 120) t.pensize(1) for i in range(180, 360): x drawX(80, i) y drawY(32, i) 120 t.goto(x, y) t.fillcolor(#ffaaa0) t.end_fill() # 13 t.pu() t.goto(64, 120) t.pd() t.pencolor(#b1c9e9) t.begin_fill() for i in range(360): x drawX(4, i) 60 y drawY(1, i) 120 t.goto(x, y) t.goto(64, 170) for i in range(540): x drawX(4, i) 60 y drawY(1, i) 170 t.goto(x, y) t.goto(56, 120) t.fillcolor(#b1c9e9) t.end_fill() t.pencolor(white) t.pensize(2) for i in range(1, 6): t.goto(64, 120 10 * i) t.pu() t.goto(56, 120 10 * i) t.pd() t.pu() t.goto(60, 170) t.pd() t.goto(60, 180) t.pensize(1) # t.pu() t.goto(64, 190) t.pd() t.pencolor(#f1add1) t.begin_fill() for i in range(360): x drawX(4, i) 60 y drawY(10, i) 190 t.goto(x, y) t.fillcolor(#f1add1) t.end_fill() # 14 t.pu() t.goto(-56, 120) t.pd() t.pencolor(#b1c9e9) t.begin_fill() for i in range(360): x drawX(4, i) - 60 y drawY(1, i) 120 t.goto(x, y) t.goto(-56, 170) for i in range(540): x drawX(4, i) - 60 y drawY(1, i) 170 t.goto(x, y) t.goto(-64, 120) t.fillcolor(#b1c9e9) t.end_fill() t.pencolor(white) t.pensize(2) for i in range(1, 6): t.goto(-56, 120 10 * i) t.pu() t.goto(-64, 120 10 * i) t.pd() t.pu() t.goto(-60, 170) t.pd() t.goto(-60, 180) t.pensize(1) # t.pu() t.goto(-56, 190) t.pd() t.pencolor(#f1add1) t.begin_fill() for i in range(360): x drawX(4, i) - 60 y drawY(10, i) 190 t.goto(x, y) t.fillcolor(#f1add1) t.end_fill() # 15 t.pu() t.goto(0, 130) t.pd() t.pencolor(#b1c9e9) t.begin_fill() for i in range(360): x drawX(4, i) y drawY(1, i) 130 t.goto(x, y) t.goto(4, 180) for i in range(540): x drawX(4, i) y drawY(1, i) 180 t.goto(x, y) t.goto(-4, 130) t.fillcolor(#b1c9e9) t.end_fill() t.pencolor(white) t.pensize(2) for i in range(1, 6): t.goto(4, 130 10 * i) t.pu() t.goto(-4, 130 10 * i) t.pd() t.pu() t.goto(0, 180) t.pd() t.goto(0, 190) t.pensize(1) # t.pu() t.goto(4, 200) t.pd() t.pencolor(#f1add1) t.begin_fill() for i in range(360): x drawX(4, i) y drawY(10, i) 200 t.goto(x, y) t.fillcolor(#f1add1) t.end_fill() # 16 t.pu() t.goto(30, 110) t.pd() t.pencolor(#b1c9e9) t.begin_fill() for i in range(360): x drawX(4, i) 30 y drawY(1, i) 110 t.goto(x, y) t.goto(34, 160) for i in range(540): x drawX(4, i) 30 y drawY(1, i) 160 t.goto(x, y) t.goto(26, 110) t.fillcolor(#b1c9e9) t.end_fill() t.pencolor(white) t.pensize(2) for i in range(1, 6): t.goto(34, 110 10 * i) t.pu() t.goto(26, 110 10 * i) t.pd() t.pu() t.goto(30, 160) t.pd() t.goto(30, 170) t.pensize(1) # t.pu() t.goto(34, 180) t.pd() t.pencolor(#f1add1) t.begin_fill() for i in range(360): x drawX(4, i) 30 y drawY(10, i) 180 t.goto(x, y) t.fillcolor(#f1add1) t.end_fill() # 17 t.pu() t.goto(-30, 110) t.pd() t.pencolor(#b1c9e9) t.begin_fill() for i in range(360): x drawX(4, i) - 30 y drawY(1, i) 110 t.goto(x, y) t.goto(-26, 160) for i in range(540): x drawX(4, i) - 30 y drawY(1, i) 160 t.goto(x, y) t.goto(-34, 110) t.fillcolor(#b1c9e9) t.end_fill() t.pencolor(white) t.pensize(2) for i in range(1, 6): t.goto(-26, 110 10 * i) t.pu() t.goto(-34, 110 10 * i) t.pd() t.pu() t.goto(-30, 160) t.pd() t.goto(-30, 170) t.pensize(1) # t.pu() t.goto(-26, 180) t.pd() t.pencolor(#f1add1) t.begin_fill() for i in range(360): x drawX(4, i) - 30 y drawY(10, i) 180 t.goto(x, y) t.fillcolor(#f1add1) t.end_fill() ###随机 color [#e28cb9, #805a8c, #eaa989, #6e90b7, #b8b68f, #e174b5, #cf737c, #7c8782] for i in range(80): t.pu() x r.randint(-120, 120) y r.randint(-25, 30) t.goto(x, y) t.pd() t.dot(r.randint(2, 5), color[r.randint(0, 7)]) for i in range(40): t.pu() x r.randint(-90, 90) y r.randint(-35, 10) t.goto(x, y) t.pd() t.dot(r.randint(2, 5), color[r.randint(0, 7)]) for i in range(40): t.pu() x r.randint(-80, 80) y r.randint(60, 90) t.goto(x, y) t.pd() t.dot(r.randint(2, 5), color[r.randint(0, 7)]) for i in range(30): t.pu() x r.randint(-50, 50) y r.randint(45, 70) t.goto(x, y) t.pd() t.dot(r.randint(2, 5), color[r.randint(0, 7)]) for i in range(50): t.pu() x r.randint(-500, 500) y r.randint(120, 300) t.goto(x, y) t.pd() t.dot(r.randint(3, 5), color[r.randint(0, 7)]) t.seth(90) t.pu() t.goto(0, 0) t.fd(210) t.left(90) t.fd(170) t.pd() t.write(Happy Birthday, font(Curlz MT, 50)) t.color(red) t.penup() t.goto(-400, 210) t.pendown() t.write(致姓名 , font(楷体, 32, bold)) t.color(red) t.penup() t.goto(-300, 50) t.pendown() t.write(祝 你 生 日 快 乐前 程 似 锦, font(楷体, 30, bold)) t.color(red) t.penup() t.goto(100, -220) t.pendown() t.write(————, font(楷体, 20, bold)) t.done()