Random fun with processing

Sweet visualization thingy here https://processing.org/.
I made a video.

https://vimeo.com/139664336

Code written using the rectangle class.

public int snakes = 500;
public int[] numholdx = new int[snakes];
public int[] numholdy = new int[snakes];
public color[] colorhold = new color[snakes];
void setup()
{
  for (int k = 0 ; k < snakes; k++)
  {
    numholdx[k] = 635;
    numholdy[k] = 363;
  }
  int swap = 0;
  for (int k = 0 ; k < snakes; k++)
  {
    switch(swap) 
    {
      case 0: 
        colorhold[k] = #f7fcfd;
        break;
      case 1: 
        colorhold[k] = #e5f5f9;
        break;
      case 2: 
        colorhold[k] = #ccece6;
        break;
      case 3: 
        colorhold[k] = #99d8c9;
        break;
      case 4: 
        colorhold[k] = #66c2a4;
        break;
      case 5: 
        colorhold[k] = #41ae76;
        break;
      case 6: 
        colorhold[k] = #238b45;
        break;
      case 7: 
        colorhold[k] = #005824;
        break;
    }
    swap +=1;
    if ( swap == 8 )
      swap = 0;
  }
  size(1280, 720);
  background(0);
}
 
void draw()
{
  for ( int line = 0; line < snakes; line ++)
  {
    fill(colorhold[line]);
    int cline = line - 1;
    if (cline == -1)
    {
      cline = 7; 
    }
      stroke(colorhold[cline]);
    int r = int(random(0,4)); 
    //random direction.
    int len_max = int(random(0,5)); 
    //direction.
    int keep_dir = r;
 
    //box size.
    int size = 2;
 
    //check border.
    if ( keep_dir == 1 && numholdy[line] < 0 )
      keep_dir = 3;
    else if ( keep_dir == 3 && numholdy[line] > 1280 )
      keep_dir = 1;
    else if ( keep_dir == 2 && numholdx[line] < 0 )
      keep_dir = 0;
    else if ( keep_dir == 0 && numholdx[line] > 1280 )
      keep_dir = 2;
    if ( keep_dir == 0)
    {
       rect( numholdx[line] + size, numholdy[line], size, size);
        numholdx[line] += size;
    }
    else if ( keep_dir == 3)
    {
        rect( numholdx[line], numholdy[line] + size,size, size);
        numholdy[line] += size;
    }
    else if ( keep_dir == 2)
    {
        rect( numholdx[line] - size, numholdy[line], size, size);
        numholdx[line] -= size;
    }
    else if ( keep_dir == 1)
    {
        rect( numholdx[line], numholdy[line]- size,size, size);
        numholdy[line] -= size;
    }
  }
 
}

Leave a Reply

Your email address will not be published. Required fields are marked *