chaos game

int n = {your input}; 
float r = {your input}; 

Point p = new Point(300, 300); 
Point[] vertices = new Point[n]; 

class Point {
      int x; 
      int y; 
      
      Point(int xp, int yp) {
        x = xp; 
	y = yp; 
      }

      void draw() {
      	rect(x-1, y-1, 2, 2); 
      }     
}

void setup() {
     size(600, 600); 
     background(0); 
     frameRate(200); 
     noStroke(); 

     colorMode(HSB, 255); 

     fill(255); 
     
     float dTheta = TWO_PI/n; 
     float theta = 0; 
     for(int i=0; i<n; i++) {
     	vertices[i] = new Point(300+300*sin(theta), 300+300*cos(theta)); 
        vertices[i].draw(); 
	theta += dTheta; 
     }     

     p.draw(); 
}

void draw() {
     p = nextpoint(vertices[randInt(0,n)], p); 
     fill((p.x/600.0)*255, (p.y/600.0)*255, 255); 
     p.draw();     
}

Point nextpoint(Point a, Point b) {
      return new Point((b.x-a.x)*r+a.x, 
      	     	       (b.y-a.y)*r+a.y); 
}

int randInt(int a, int b) {
    return int(random(a,b)); 
}

void restart_animation(int u_n, float u_r) {
     n = u_n; 
     r = u_r; 
     vertices = new Point[n]; 
     setup(); 
}