亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? cellsgrid.java

?? 使用Java3D編寫的生命棋游戲??赏献髽烁淖円暯恰?
?? JAVA
字號:

// CellsGrid.java
// Andrew Davison, July 2006, ad@fivedots.coe.psu.ac.th

/* CellsGrid manages a GRID_LEN * GRID_LEN * GRID_LEN grid of
   Cell objects centered at (0,0,0) in the scene.

   TimeBehavior periodically calls CellsGrid's update() method
   to update the grid. An update will either trigger a state change 
   or a visual change. 

   A state change changes the grid's
   cells state by applying birth and die ranges. These ranges
   are a 3D version of the rules used in Conway's Game of Life
   and other cellular automata.

   Most updates trigger visual changes to the cells, which
   affect their visibility and colour. A visual transition
   is spread out over MAX_TRANS updates.

   Every update causes the grid to rotate, although the rotation
   axis is periodically changed, so the grid moves in a
   random way.

   The birth and die ranges, and the rotation speed, are specified
   by properties obtained from the lifeProps object. 
*/

import java.util.*;

import com.sun.j3d.utils.geometry.*;
import javax.media.j3d.*;
import javax.vecmath.*;


public class CellsGrid
{
  // grid rotation amount 
  private static final double ROTATE_AMT = Math.toRadians(4);  // 4 degrees

  // number of updates used to complete a visual transition (used by Cell class)
  public static final int MAX_TRANS = 8;

  // number of cells along the x-, y-, and z- axes
  private final static int GRID_LEN = 10;  

  // storage for the cells making up the grid
  private Cell[][][] cells;

  // reusable Transform3D object
  private Transform3D t3d = new Transform3D(); 
  private Transform3D rotT3d = new Transform3D();

  private TransformGroup baseTG;   // used to rotate the grid
  private double turnAngle;
  private int turnAxis = 0;

  // transition (transparency/colour change) step counter
  private int transCounter = 0;

  private LifeProperties lifeProps;

  // birth and die ranges used in the life rules
  boolean[] birthRange, dieRange;

  private Random rand = new Random();



  public CellsGrid(LifeProperties lps)
  /* The grid (3D array) of Cells is created, and are connected
     to a baseTG TransformGroup. When baseTG is rotated at run 
     time, the entire grid moves. 
  */
  { 
    lifeProps = lps;

    // load birth and die ranges
    birthRange = lifeProps.getBirth();
    dieRange = lifeProps.getDie();

    setTurnAngle();

    /* Allow baseTG to be read and changed at run time (so
       it can be rotated). */
    baseTG = new TransformGroup();   
    baseTG.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    baseTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

    // initialize the grid with Cell objects
    cells = new Cell[GRID_LEN][GRID_LEN][GRID_LEN];
    for (int i=0; i < GRID_LEN; i++) 
      for (int j=0; j < GRID_LEN; j++)
        for (int k=0; k < GRID_LEN; k++) {
          cells[i][j][k] = 
				new Cell(i-GRID_LEN/2, j-GRID_LEN/2, k-GRID_LEN/2);  // so grid is centered
          baseTG.addChild( cells[i][j][k].getTG() );  // connect cell to baseTG
        }
  }  // end of CellsGrid()


  private void setTurnAngle()
  /* A faster speed property is converted into a larger 
     rotation angle, which makes the grid turn faster at
     tun time. */
  {
    int speed = lifeProps.getSpeed();

    if (speed == LifeProperties.SLOW)
      turnAngle = ROTATE_AMT/4;
    else if (speed == LifeProperties.MEDIUM)
      turnAngle = ROTATE_AMT/2;
    else  // fast --> large rotation
      turnAngle = ROTATE_AMT;
  }  // end of setTurnAngle()


  public TransformGroup getBaseTG()
  {  return baseTG;  } 


  // ------------------------ update the grid ------------------------

  public void update()
  /* An update() call either triggers a state change or a visual
     change. update() is called periodically by TimeBehavior.

     The transCounter is incremented from 0 to MAX_TRANS, then
     repeats. When transCounter is 0, the state of the grid's 
     cells is updated, and the grid's rotation axis changed.

     At other times, the cells' visuals are changed, which may 
     mean their visibility and/or colour changing.

     At every update, the grid is rotated. 
  */
  {
    if (transCounter == 0) {   // time for grid state change
      stateChange();
      turnAxis = rand.nextInt(3);  // change rotation axis
      transCounter = 1;
    }
    else {   // make a visual change
      for (int i=0; i < GRID_LEN; i++)
        for (int j=0; j < GRID_LEN; j++)
          for (int k=0; k < GRID_LEN; k++)
            cells[i][j][k].visualChange(transCounter);

      transCounter++;
      if (transCounter > MAX_TRANS)
        transCounter = 0;   // finished, so reset
    }

    doRotate();   // rotate in every update() call
  }  // end of update()


  private void stateChange()
  /* A two phase operation: first calculate the next life state
     for each cell, then update the cells
  */
  {
    boolean willLive;

    // calculate next state for each cell
    for (int i=0; i < GRID_LEN; i++)
      for (int j=0; j < GRID_LEN; j++)
        for (int k=0; k < GRID_LEN; k++) {
          willLive = aliveNextState(i, j, k);
          cells[i][j][k].newAliveState(willLive);
        }

    // update each cell
    for (int i=0; i < GRID_LEN; i++)
      for (int j=0; j < GRID_LEN; j++)
        for (int k=0; k < GRID_LEN; k++) {
          cells[i][j][k].updateState();
          cells[i][j][k].visualChange(0);
        }
  }  // end of stateChange()


  // ---------------------- life calculations ------------------------


  private boolean aliveNextState(int i, int j, int k)
  /* The life calculation depends on the number of neigbouring cells
     which are currently alive, which is stored in numberLiving.

     The next state for cell[i][j[k] depends on it's current alive
     state and whether numberLiving appears in the birth or die
     ranges. These ranges are specified when Life3D is being 
     configured.
  */
  {
    // count all the living neighbours, but not the cell itself
    int numberLiving = 0;
    for(int r=i-1; r <= i+1; r++)  // range i-1 to i+1
      for(int s=j-1; s <= j+1; s++)  // range j-1 to j+1
        for(int t=k-1; t <= k+1; t++) {  // range k-1 to k+1
          if ((r==i) && (s==j) && (t==k))
            continue;   // skip self
          else if (isAlive(r,s,t))
            numberLiving++;
        }

    // get the cell's current life state
    boolean currAliveState = isAlive(i,j,k);

    // ** Life Rules **: calculate the cell's next life state
    if (birthRange[numberLiving] && !currAliveState)   // to be born && dead now
      return true;   // make alive
    else if (dieRange[numberLiving]  && currAliveState)  // to die && alive now
      return false;  // kill off
    else
      return currAliveState;  // no change
  }  // end of aliveNextState()


  private boolean isAlive(int i, int j, int k)
  {
    // deal with edge cases for cells array
    i = rangeCorrect(i);
    j = rangeCorrect(j);
    k = rangeCorrect(k);
    return  cells[i][j][k].isAlive();
  }  // end of isAlive()


  private int rangeCorrect(int index)
  /* if the cell index is out of range then use the index of
     the opposite edge */
  {
    if (index < 0)
      return (GRID_LEN + index);
    else if (index > GRID_LEN-1)
      return (index - GRID_LEN);
    else // make no change
      return index;
  }  // end of rangeCorrect()


  // ------------------- rotation ------------------------------


  private void doRotate()
  // rotate the object turnAngle radians around an axis
  {
    baseTG.getTransform(t3d);  // get current rotation
    rotT3d.setIdentity();      // reset the rotation transform object

    switch (turnAxis) {    // set the rotation based on the current axis
      case 0: rotT3d.rotX(turnAngle); break;
      case 1: rotT3d.rotY(turnAngle); break;
      case 2: rotT3d.rotZ(turnAngle); break;
      default: System.out.println("Unknown axis of rotation"); break;
    }

    t3d.mul(rotT3d);            // 'add' new rotation to current one
    baseTG.setTransform(t3d);   // update the TG
  }  // end of doRotate()


}  // end of CellsGrid class

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
91精品国产色综合久久不卡蜜臀| 福利一区二区在线| 欧美群妇大交群中文字幕| 一区二区在线观看免费| 91欧美一区二区| 亚洲午夜激情网页| 7777女厕盗摄久久久| 美女高潮久久久| 久久久不卡网国产精品二区 | 亚洲黄色性网站| 欧洲视频一区二区| 丝袜美腿亚洲一区二区图片| 宅男在线国产精品| 国产精品一区二区久激情瑜伽| 欧美国产精品专区| 青青草国产精品97视觉盛宴| 精品久久人人做人人爰| 成人免费看的视频| 亚洲香肠在线观看| 精品动漫一区二区三区在线观看| 国产成人综合精品三级| 一区二区不卡在线视频 午夜欧美不卡在 | 国产最新精品精品你懂的| 国产三级一区二区| 在线观看免费一区| 精品一区二区三区免费| 亚洲图片另类小说| 日韩欧美一级在线播放| www.亚洲在线| 日韩国产成人精品| 中文字幕高清一区| 欧美欧美午夜aⅴ在线观看| 国产精品一区二区久久不卡 | 丁香一区二区三区| 午夜精品久久久久久久久| 久久久久久久久久美女| 欧美综合视频在线观看| 韩国女主播一区二区三区| 夜夜操天天操亚洲| 久久精品日产第一区二区三区高清版 | 久久欧美一区二区| 欧美优质美女网站| 国产精品一二三四| 日韩av一级电影| 亚洲精品写真福利| 国产亚洲制服色| 制服丝袜中文字幕亚洲| 国产69精品久久777的优势| 亚洲第一综合色| 中文字幕一区av| 久久久久久久久免费| 91麻豆精品91久久久久久清纯 | 一本一本大道香蕉久在线精品| 美腿丝袜亚洲一区| 亚洲国产精品综合小说图片区| 国产欧美精品区一区二区三区 | 99视频精品在线| 国产一区二区三区日韩| 欧美96一区二区免费视频| 亚洲精品videosex极品| 国产精品久久久久影院| 久久蜜桃av一区二区天堂| 日韩一级完整毛片| 制服丝袜一区二区三区| 欧美日韩一本到| 欧美亚洲图片小说| 91麻豆免费在线观看| 成人免费观看av| 国产99精品国产| 成人三级伦理片| 成人影视亚洲图片在线| 国产精品99久久久久| 国内精品免费**视频| 国产在线看一区| 国产在线不卡一卡二卡三卡四卡| 麻豆国产精品视频| 另类专区欧美蜜桃臀第一页| 喷水一区二区三区| 卡一卡二国产精品 | 亚洲综合久久av| 一二三四区精品视频| 亚洲女爱视频在线| 亚洲欧美另类久久久精品2019| 成人免费在线播放视频| 亚洲三级在线免费观看| 最新国产の精品合集bt伙计| 中文字幕一区二区三| 亚洲美女视频在线观看| 亚洲一区二区三区中文字幕 | 国产精品久久久久久久久免费丝袜 | 26uuu精品一区二区在线观看| 欧美一二三区在线| 精品免费视频.| 国产视频视频一区| 亚洲色图清纯唯美| 亚洲va欧美va天堂v国产综合| 偷拍自拍另类欧美| 久久成人免费网| 国产成人精品一区二区三区四区| 岛国av在线一区| 91久久精品网| 3d动漫精品啪啪| 久久精品人人做人人综合| 自拍偷在线精品自拍偷无码专区| 一区二区三区产品免费精品久久75| 亚洲1区2区3区视频| 极品销魂美女一区二区三区| 成人激情av网| 欧美日韩一区二区电影| 日韩美女天天操| 国产精品美女一区二区| 五月婷婷综合激情| 国产精品一区久久久久| 91福利在线导航| 精品国产乱码久久久久久浪潮| 国产精品色哟哟网站| 亚洲成av人综合在线观看| 国产精品影视在线观看| 在线亚洲精品福利网址导航| 欧美一区二区三区婷婷月色| 国产欧美日韩视频在线观看| 午夜激情久久久| 懂色一区二区三区免费观看| 欧美日韩高清影院| 久久免费电影网| 亚洲成人动漫一区| 成人午夜视频免费看| 欧美日韩中文字幕一区| 日本一区二区三区四区| 日韩高清不卡一区二区| 成人av影院在线| 精品剧情v国产在线观看在线| 亚洲精品视频观看| 国产精品一区专区| 56国语精品自产拍在线观看| 成人欧美一区二区三区1314| 国产在线播精品第三| 在线播放中文字幕一区| 亚洲素人一区二区| 国产精品综合av一区二区国产馆| 欧美性生活久久| 中文字幕在线播放不卡一区| 国产精品一级黄| 欧美成人免费网站| 亚洲成a人片在线观看中文| 99九九99九九九视频精品| 欧美大肚乱孕交hd孕妇| 亚洲电影一级黄| 在线观看91精品国产入口| 中文字幕成人av| 国产麻豆91精品| 精品日韩在线观看| 三级精品在线观看| 欧美在线视频你懂得| 亚洲天堂a在线| av成人老司机| 国产精品美日韩| 不卡av电影在线播放| 久久九九影视网| 极品少妇xxxx精品少妇| 日韩欧美在线网站| 日韩va欧美va亚洲va久久| 欧美日韩精品免费观看视频 | 中文字幕欧美三区| 国产一区二区剧情av在线| 久久亚洲一区二区三区明星换脸 | 一区二区三区日本| 91丨porny丨首页| 18欧美乱大交hd1984| av高清不卡在线| 亚洲欧美日韩国产成人精品影院| 99久久国产综合精品色伊| 国产精品美女www爽爽爽| 成人小视频在线观看| 亚洲三级理论片| 欧美私人免费视频| 日韩专区中文字幕一区二区| 欧美一区二区久久久| 久久99久久久欧美国产| 久久一二三国产| 成人永久aaa| 亚洲一区二区3| 91精品国产色综合久久不卡电影| 日韩av中文字幕一区二区| 精品久久国产字幕高潮| 国产激情精品久久久第一区二区| 欧美激情一区二区三区在线| 99精品偷自拍| 午夜影视日本亚洲欧洲精品| 日韩午夜av一区| 成人丝袜高跟foot| 一级中文字幕一区二区| 欧美一区二区免费| 高清不卡一区二区| 亚洲精品成人天堂一二三| 欧美二区乱c少妇| 国产一区欧美一区| 亚洲免费视频中文字幕| 欧美一区在线视频| 国产精品一区2区|