basic Classes problem
in
Programming Questions
•
11 months ago
[edit] SOLVED by Chrisir, many thanks [/edit]
- code is modified from Shiffman's Nature of Code ex1.5
- perlinWalker[] walkers = new perlinWalker[5];
- void setup(){
- size(500,500);
- background(0);
- for(int i = 0; i < walkers.length; i++){
- walkers[i] = new perlinWalker();
- }
- }
- void draw(){
- for(int i = 0; i < walkers.length; i++){
- walkers[i].step();
- walkers[i].display();
- }
- }
- class perlinWalker{
- float x, y;
- float tx, ty;
- int r,g,b;
- float stepSize;
- perlinWalker(){
- x = int(random(width/2));
- y = int(random(height/2));
- stepSize = 0.01;
- tx = 0;
- ty = 1000;
- r = int(random(255));
- g = int(random(255));
- b = int(random(255));
- }
- void display(){
- stroke(r,g,b);
- ellipse(x,y,20,20);
- }
- void step(){
- x = map(noise(tx),0,1,0,width);
- y = map(noise(ty),0,1,0,width);
- tx += stepSize;
- ty += stepSize;
- }
- }
1