بدون مزيد من اللغط، سأقوم بنشر كود جافا لك.
import java.awt.Color; import java.awt.Graphics; import java.awt.image.BufferedImage; import javax.swing.JPanel; (~) عدد النيازك Final int SLEEP = ; // سرعة طيران النيزك (كلما زادت القيمة، كانت السرعة أبطأ) Final int COLORLV = // ; (~) مقياس اللون (يمكن تغيير حجم الهالة) Final String COLOR = null; // ("#"~"#ffffff") لون الهالة (إذا لم يكن مملوءًا أو فارغًا، فهو اللون الافتراضي) Final int SIZE = ; // (~) لوحة MyPanel الخاصة؛ public MeteorFly() { Panel = new MyPanel(); this.getContentPane().add(panel); أنشئ نموذجًا this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setVisible(true); } public static void main(String[] args) { new MeteorFly(); AppletWidth، AppletHeight؛ BufferedImage OffScreen؛ drawOffScreen; Thread pThread; public MyPanel() { setBackground(Color.black); ] = new Meteor(); new BufferedImage(AppletWidth, AppletHeight, BufferedImage.TYPE_INT_BGR); drawOffScreen = OffScreen.getGraphics(); pThread = new Thread(this); g); g.drawImage(OffScreen, , this } @Override الفراغ العام النهائي run() { while (true) { // drawOffScreen.clearRect(, , AppletWidth, AppletHeight) // // امسح الشاشة for (int i = ; i < MAX; i++) { drawOffScreen.setColor(p[i]); .color)؛ // لون RGB drawOffScreen.fillOval(p[i].x, p[i].y, SIZE, SIZE); p[i].x += p[i].mx; p[i].y += p[i].my; > AppletHeight) { // p[i].reset(); // } int x = p[i].x; ); // استخراج اللون int G = p[i].color.getGreen(); int B = p[i].color.getBlue(); while (true) { if (R == && G == && B == ) { } R -= COLORLV; // تلاشي لون الذيل if (R < ) { R = } G -= COLORLV; { B = } Color color = new Color(R, G, B); x -= p[i].mx; drawOffScreen .fillOval(x, y, SIZE, SIZE) } if (x > AppletWidth || y > AppletHeight) { // يطير النيزك من النافذة، قم بإعادة ضبط النيزك p[i].reset(); } } repaint(); حاول { Thread.sleep(SLEEP); e.printStackTrace (); } } } } class Meteor { // فئة النيزك int x, y; // موضع النيزك int mx, my; color; // لون النيزك public Meteor() {set(); } public voidset() { int rand = (int) (Math.random() * ); // إنشاء موقع النيزك بشكل عشوائي if (rand > ) { x = (int) (Math.random() * ); y = } else { y = (int) (Math.random() * } mx = (int) (Math.random() * + ); // توليد سرعة السقوط وزاوية عشوائيًا my = (int) (Math.random() * + ); if (COLOR == null || COLOR.length() == ) { color = new Color( // لون عشوائي (new Double(Math.random() * )).intValue() + , (new Double(Math.random() * )).intValue() + , (جديد Double(Math.random() * )).intValue() + } else { color = Color.decode(COLOR);الكود أعلاه هو كود Java النقي الذي تخبرك به هذه المقالة لتنفيذ النيازك عبر السماء. آمل أن تجلب لك مشاركة هذه المقالة مكاسب غير متوقعة.