欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

純Java代碼實現(xiàn)流星劃過天空

 更新時間:2015年10月29日 09:41:26   作者:_Nick  
本文給大家介紹純java代碼實現(xiàn)流星劃過天空,包括流星個數(shù),流星飛行的速度,色階,流星大小相關(guān)變量設(shè)置。對java流星劃過天空特效代碼感興趣的朋友可以參考下本文

廢話不多說了,直接給大家貼java代碼了。

import java.awt.Color;
  import java.awt.Graphics;
  import java.awt.image.BufferedImage;
  import javax.swing.JFrame;
  import javax.swing.JPanel;
  public class MeteorFly extends JFrame {
   final int MAX = ; // (~)流星的個數(shù)
   final int SLEEP = ; // 流星飛行的速度(數(shù)值越大,速度越慢)
   final int COLORLV = ; // (~)色階(可改變光暈大?。?
   final String COLOR = null; // ("#"~"#ffffff")光暈顏色(如果不填或null,則為默認顏色)
   final int SIZE = ; // (~)流星大小
   private MyPanel panel;
   public MeteorFly() {
   panel = new MyPanel();
   this.getContentPane().add(panel);
   this.setSize(, ); // 創(chuàng)建窗體
   this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   this.setVisible(true);
   }
   public static void main(String[] args) {
   new MeteorFly();
   }
   class MyPanel extends JPanel implements Runnable {
   Meteor p[];
   int AppletWidth, AppletHeight;
   BufferedImage OffScreen;
   Graphics drawOffScreen;
   Thread pThread;
   public MyPanel() {
     setBackground(Color.black); //窗體初始化
     AppletWidth = ;
     AppletHeight = ;
     p = new Meteor[MAX];
     for (int i = ; i < MAX; i++)
     p[i] = new Meteor();
     OffScreen = new BufferedImage(AppletWidth, AppletHeight,
       BufferedImage.TYPE_INT_BGR);
     drawOffScreen = OffScreen.getGraphics();
     pThread = new Thread(this);
     pThread.start();
   }
   @Override
   public void paintComponent(Graphics g) {
     // TODO Auto-generated method stub
     super.paintComponents(g);
     g.drawImage(OffScreen, , , this);
   }
   @Override
   final public void 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 R = p[i].color.getRed(); // 提取顏色
       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;
       if (B < ) {
         B = ;
       }
       Color color = new Color(R, G, B);
       x -= p[i].mx; // 覆蓋尾部
       y -= p[i].my;
       drawOffScreen.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 Auto-generated catch block
       e.printStackTrace();
     }
     }
   }
   }
   class Meteor { // 流星類
   int x, y; // 流星的位置
   int mx, my; // 下落速度
   Color color; // 流星顏色
   public Meteor() {
     reset();
   }
   public void reset() {
     int rand = (int) (Math.random() * ); //隨機生成流星出現(xiàn)位置
     if (rand > ) {
     x = (int) (Math.random() * );
     y = ;
     } else {
     y = (int) (Math.random() * );
     x = ;
     }
     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代碼實現(xiàn)流星劃過天空,希望本文分享能夠給大家?guī)硪庀氩坏降氖斋@。

相關(guān)文章

  • java解析JSON數(shù)據(jù)詳解

    java解析JSON數(shù)據(jù)詳解

    這篇文章主要介紹了java解析JSON數(shù)據(jù)詳解,具有一定借鑒價值,需要的朋友可以參考下。
    2017-12-12
  • SpringCloud Nacos作為配置中心超詳細講解

    SpringCloud Nacos作為配置中心超詳細講解

    這篇文章主要介紹了Springcloud中的Nacos作為配置中心,本文以用戶微服務(wù)為例,進行統(tǒng)一的配置,結(jié)合實例代碼給大家介紹的非常詳細,需要的朋友可以參考下
    2022-12-12
  • java基礎(chǔ)教程之拼圖游戲的實現(xiàn)

    java基礎(chǔ)教程之拼圖游戲的實現(xiàn)

    拼圖游戲大家應(yīng)該都玩過,下面這篇文章主要給大家介紹了關(guān)于java基礎(chǔ)教程之拼圖游戲的實現(xiàn)方法,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下
    2022-01-01
  • 詳解SpringBoot自定義配置與整合Druid

    詳解SpringBoot自定義配置與整合Druid

    Druid是alibaba開源平臺上一個數(shù)據(jù)庫連接池實現(xiàn),結(jié)合了C3P0,DBCP等DB池的優(yōu)點,同時也有Web監(jiān)控界面。這篇文章主要介紹了Java之SpringBoot自定義配置與整合Druid的相關(guān)知識,需要的朋友可以參考下
    2021-09-09
  • springsecurity中http.permitall與web.ignoring的區(qū)別說明

    springsecurity中http.permitall與web.ignoring的區(qū)別說明

    這篇文章主要介紹了springsecurity中http.permitall與web.ignoring的區(qū)別說明,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-08-08
  • Java使用JDK與Cglib動態(tài)代理技術(shù)統(tǒng)一管理日志記錄

    Java使用JDK與Cglib動態(tài)代理技術(shù)統(tǒng)一管理日志記錄

    這篇文章主要介紹了Java使用JDK與Cglib動態(tài)代理技術(shù)統(tǒng)一管理日志記錄,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-05-05
  • 深入學習JavaWeb中監(jiān)聽器(Listener)的使用方法

    深入學習JavaWeb中監(jiān)聽器(Listener)的使用方法

    這篇文章主要為大家詳細介紹了深入學習JavaWeb中監(jiān)聽器(Listener)的使用方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-09-09
  • 動力節(jié)點_王勇_DRP項目視頻教程完整版292集

    動力節(jié)點_王勇_DRP項目視頻教程完整版292集

    該視頻由國內(nèi)知名講師王勇老師主講,適合掌握Java基礎(chǔ)內(nèi)容的同學學習,本視頻共計292集,學習Java Web項目,DRP項目視頻是首選,累計下載量已經(jīng)達到上千萬,很多同學通過自學該視頻找到了軟件開發(fā)工作
    2017-04-04
  • Java面向?qū)ο笾蓡T隱藏與屬性封裝操作示例

    Java面向?qū)ο笾蓡T隱藏與屬性封裝操作示例

    這篇文章主要介紹了Java面向?qū)ο笾蓡T隱藏與屬性封裝操作,結(jié)合實例形式分析了Java面向?qū)ο蟪绦蛟O(shè)計中成員的隱藏及屬性封裝相關(guān)實現(xiàn)與使用操作技巧,需要的朋友可以參考下
    2018-06-06
  • idea?maven?經(jīng)常主目錄自動變回默認的解決方法

    idea?maven?經(jīng)常主目錄自動變回默認的解決方法

    很多朋友反映idea?maven?經(jīng)常主目錄自動變回默認,遇到這樣的問題真的很頭疼,該如何解決呢?下面小編給大家介紹下idea?maven目錄變回默認的解決方法,需要的朋友可以參考下
    2022-08-08

最新評論