早速、Java コードを投稿します。
インポート java.awt.Color; インポート java.awt.image.BufferedImage; インポート javax.swing.JPanel; public class MeteorFly を拡張します。 (~)流星の数final int SLEEP = ; // 流星の飛行速度(値が大きいほど遅くなります)final int COLORLV = ; (~) カラースケール (ハローのサイズを変更できます) Final String COLOR = null // ("#"~"#ffffff") ハローの色 (未入力または null の場合、デフォルトの色です) Final int SIZE = ; // (~) メテオのサイズ private MyPanel () { パネル = new MyPanel(); //フォームを作成します this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setVisible(true); } public static void main(String[] args) { new MeteorFly() } class MyPanel は Runnable { Meteor p[]; を作成します。アプレット幅、アプレット高さ、オフスクリーン グラフィックス; drawOffScreen; public MyPanel() { setBackground(Color.black); // フォームの初期化 AppletWidth = ; p = new Meteor[MAX] for (int i = ; i < MAX; i++) ] = 新しい Meteor(); = 新しい BufferedImage(AppletWidth, AppletHeight, BufferedImage.TYPE_INT_BGR);drawOffScreen = OffScreen.getGraphics(); pThread = new Thread(this); } @Override public voidPaintComponent(Graphics g) { // TODO 自動生成メソッド スタブ super.paintComponents( g); g.drawImage(OffScreen, , , this) } @Override Final public void run() { while (true) { //drawOffScreen.clearRect(, , AppletWidth, AppletHeight) // // (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 // if (p[i].x > AppletWidth || p[i].y; > AppletHeight) { // p[i].reset(); // } int x = p[i].x; int y = p[i].getRed( ); //色の抽出 int G = p[i].color.getGreen(); int B = p[i].color.getBlue(); if (R == && G == && B == ); Break; } R -= COLORLV; // テールカラー if (R < ) { R = ; } B -= COLORLV; { B = ; } カラー color = new Color(R, G, B); x -= p[i].mx; // 末尾をカバーします y -= p[i].setColor(color); drawOffScreen .fillOval(x, y, SIZE, SIZE) } if (x > AppletWidth || y > AppletHeight) { //流星が窓から飛び出す、流星をリセットする p[i].reset(); } } repaint(); try { Thread.sleep(SLEEP) } catch (InterruptedException e) { // TODO 自動生成された catch ブロックe.printStackTrace (); } } } } class Meteor { // 流星の位置 int mx, my; color; // 流星の色 public Meteor() { replace(); } public void replace() { int rand = (int) (Math.random() * ); // 流星の位置をランダムに生成する if (rand > ) { x = (int) (Math.random() * ); } 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() + , (new Double(Math.random() * )).intValue() + ); } else { color = Color.decode(COLOR);上記のコードは、この記事が空を横切る流星を実装するために説明する純粋な Java コードです。この記事を共有することで予期せぬ利益がもたらされることを願っています。