////////////////////// パラメータ///////////////////////////////// boolean Debug = false; // デバッグ int DirectionNum = 4; // 移動方向。4か8 int DotNum_init = 5; // 最初のドットの数 ///////////////////////// 定数 /////////////////////////////////// int TurnTiming = 30; // 曲がるタイミング // ドットの数関係 int DotNum_min = 5; int DotNum_max = DotNum_min * 10; // 画面描画設定 int MyWidth = 400; int MyHeight = 300; color BgColor = color(255, 255, 255); color DotColor = color(0, 0, 0); int DotSize = 2; ///////////////////////// 変数 /////////////////////////////////// int dotNum = DotNum_init; dot[] randomDot; myDot userDot; ///////////////////// 自動点クラス /////////////////////////////// class dot { int x, y; int dx, dy; color c; int r; dot() { x = (int)random(width); y = (int)random(height); dx = int(random(3)) - 1; dy = int(random(3)) - 1; r = DotSize; } void dotDraw() { ellipse(x, y, r, r); } void dotMove() { x += dx; if(x > width) x = 0; if(x < 0) x = width; y += dy; if(y > height) y = 0; if(y < 0) y = height; } void dotTurn() { if((int)random(TurnTiming) == 0){ switch((int)random(5)){ case 0: break; case 1: dx = 1; dy = 0; break; case 2: dx = -1; dy = 0; break; case 3: dx = 0; dy = 1; break; case 4: dx = 0; dy = -1; break; } } } } ///////////////////// 手動点クラス /////////////////////////////// class myDot extends dot { int d = 2; myDot(){ r = 5; } void control(int keyCode) { if(keyCode == UP){ dx = 0; dy = -1; } if(keyCode == DOWN){ dx = 0; dy = 1; } if(keyCode == LEFT){ dx = -1; dy = 0; } if(keyCode == RIGHT){ dx = 1; dy = 0; } if(x > width) x = 0; if(x < 0) x = width; if(y > height) y = 0; if(y < 0) y = height; } void dotDraw() { if(Debug) r = 5; else r = DotSize; super.dotDraw(); } } //////////////////// 初期設定・準備 ////////////////////////////// void setup(){ size(MyWidth, MyHeight); // ウィンドウの作成 // 描画設定 ellipseMode(CENTER); fill(DotColor); randomSeed(int(random(65536))); randomDot = new dot[DotNum_max]; for(int i = 0; i < DotNum_max; i++) randomDot[i] = new dot(); userDot = new myDot(); } void draw() { background(BgColor); for(int i = 0; i < dotNum; i++){ randomDot[i].dotDraw(); randomDot[i].dotMove(); randomDot[i].dotTurn(); } userDot.dotDraw(); userDot.dotMove(); if(!keyPressed){ userDot.dotTurn(); } } /////////////////////// キー操作 ///////////////////////////////// void keyPressed() { userDot.control(keyCode); } void keyReleased() { for(int i = 0; i < 10; i++){ if(key == '0' + i) dotNum = (i + 1) * DotNum_min; } if(keyCode == ENTER){ if(Debug) Debug = false; else Debug = true; println(Debug); } }