더 이상 고민하지 않고 Java 코드만 게시해 드리겠습니다.
import java.awt.Color; import java.awt.image.BufferedImage; import javax.swing.JPanel; public class MeteorFly는 JFrame을 확장합니다. // (~)유성의 수 final int SLEEP = ; // 유성의 비행 속도(값이 클수록 속도가 느려짐) final int COLORLV = ; (~) 색상 스케일(후광 크기 변경 가능) final String COLOR = null; // ("#"~"#ffffff") 후광 색상(입력하지 않거나 null인 경우 기본 색상) final int SIZE = ; // (~) 유성 크기 private MyPanel panel; public MeteorFly() { panel = new MyPanel(); this.setSize(, ); 양식 만들기 this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setVisible(true); } public static void main(String[] args) { new MeteorFly() } class MyPanel은 Runnable을 구현합니다. { Meteor p[]; AppletWidth, AppletHeight; 버퍼링된 이미지 오프스크린 그래픽; drawOffScreen; public MyPanel() { setBackground(Color.black); //양식 초기화 AppletWidth = ; p = new Meteor[MAX] for (int i = ; i < MAX; i++) ] = new Meteor(); OffScreen = 새로운 BufferedImage(AppletWidth, AppletHeight, BufferedImage.TYPE_INT_BGR); drawOffScreen = OffScreen.getGraphics(); pThread = new Thread(this); pThread.start(); } @Override public void PaintComponent(Graphics g) { // TODO 자동 생성 메서드 super.paintComponents( 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; // if (p[i].x > AppletWidth || p[i].y > AppletHeight) { // p[i].reset(); // } int x = p[i].x int y = p[i].y; ); 색상 추출 int G = p[i].color.getGreen(); int B = p[i].color.getBlue(); while (true) { if (R == && G == && B == ) break; } R -= COLORLV; // 꼬리 색상 퇴색 if (R < ) { R = ; } G -= COLORLV; if (G < ) { G = } 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 x, y; // 유성 위치 int mx, my; color; // 유성 색상 public Meteor() { Reset(); } public void Reset() { 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() + , (new Double(Math.random() * )).intValue() + ) } else { color = Color.decode(COLOR) } } } }위의 코드는 하늘을 가로지르는 유성을 구현하기 위해 이 기사에서 설명하는 순수 Java 코드입니다. 이 기사를 공유하면 예상치 못한 이점을 얻을 수 있기를 바랍니다.