最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時間:2015年10月29日 09:41:26   作者:_Nick  
本文給大家介紹純java代碼實現(xià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ī)硪庀氩坏降氖斋@。

相關文章

最新評論

云安县| 芦溪县| 凉山| 赣榆县| 沈丘县| 内江市| 闽侯县| 马龙县| 台东县| 图片| 揭西县| 昌平区| 大方县| 泰兴市| 聊城市| 汪清县| 内黄县| 海伦市| 辽阳县| 工布江达县| 那曲县| 壶关县| 定日县| 高唐县| 临泉县| 普陀区| 北票市| 葫芦岛市| 晋州市| 广汉市| 大新县| 太谷县| 台北市| 姜堰市| 霸州市| 阿尔山市| 和顺县| 长沙县| 利津县| 个旧市| 沽源县|