[ Video ]
[ About ]
Processing勉強会の課題「分岐」
[ Source ]
| 
					 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27  | 
						int numberOfWalker = 30; Walker[] walkers = new Walker[numberOfWalker]; void setup(){   size(720, 720);   frameRate(60);   stroke(39);   strokeWeight(2);   for(int i = 0; i < numberOfWalker; i++){     walkers[i] = new Walker();   } } void draw(){   background(239);   for(int i = 0; i < numberOfWalker; i++){     walkers[i].update();     walkers[i].display();   } }  | 
					
| 
					 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70  | 
						class Walker{   PVector location;   PVector direction;   //PVector log;   ArrayList<PVector> log;   Walker(){     int x = ((int)random(0, width) / 30) * 30;     int y = ((int)random(0, height) / 30) * 30;     this.location = new PVector(x, y);     log = new ArrayList<PVector>();   }   void update(){     if(frameCount % 10 == 1){       int r = (int)random(0, 4);         switch(r){           case 0:             this.direction = new PVector(10, 0);             break;           case 1:             this.direction = new PVector(-10, 0);             break;           case 2:             this.direction = new PVector(0, 10);             break;           case 3:             this.direction = new PVector(0, -10);             break;         }     }     this.location.add(this.direction);     if(this.location.x < 0){       this.location.x = width;     }else if(this.location.x > width){       this.location.x = 0;     }     if(this.location.y < 0){       this.location.y = height;     }else if(this.location.y > height){       this.location.y =  0;     }     this.log.add(this.location.copy());     if(log.size() > 10){       this.log.remove(0);     }   }   void display(){     for(int i = 1;i < this.log.size(); i++){       line(this.log.get(i - 1).x, this.log.get(i - 1).y, this.log.get(i).x, this.log.get(i).y);      }   } }  |