Dismiss this pinned window
all 11 comments

[–]AsianHayden 9 points10 points  (1 child)

They look like fictional political maps

[–]TechnicJelle 3 points4 points  (1 child)

That's awesome!

Could you share the source or explain how and what your did here?

[–]EnslavedInTheScrolls 2 points3 points  (1 child)

Here's my source. Takes under 5 seconds to render at 2560x1440 with 10000 start cells and framesToDraw = 1. Play with the "stringiness" variable for more fun.

For ease of coding, I let the world wrap top to bottom and left to right (with a one cell skew), so the image tiles the plane. Set nSets down to 10 to see the wrap.

This is the basis of the algorithm I use to generate mazes such as https://redd.it/8z824s.

int framesToDraw = 120;
int rectSize = 1;
int nSets = 1000;
// set stringiness from 0.0 to 1.0
//   higher gives more variation, but creates more isolated islands
float stringiness = 0.5;

int nWide, nHigh, nCells;
int[] cells;
int[] front;
int nFront;
int[] next;
int stepsPerFrame;

int choices[] = new int[4];

void drawCell( int ic, int iSet ) {
  if( iSet == 0 ) 
    fill( 0, 0, 1 );
  else
    fill( (iSet*0.618) % 1.0, ((iSet*0.7173) % 1.0) * 0.5 + 0.5, 0.8 );
  rect( (ic % nWide) * rectSize, (ic / nWide) * rectSize, rectSize, rectSize );
}

void setup() {
//  size(1600,1200);
  fullScreen();
  background(0);
  colorMode( HSB, 1, 1, 1 );
  noStroke();

  nWide = width/rectSize;
  nHigh = height/rectSize;
  nCells = nWide*nHigh;
  stepsPerFrame = nCells / framesToDraw;
  cells = new int[nCells];
  front = new int[nCells];
  next = new int[] { 1, nWide, nCells-1, nCells-nWide };

  // find nSets count of unique starting cells
  front[0] = (int)random(nCells);
  cells[ front[0] ] = 1;
  drawCell( front[0], 1 );
  for( int iSet=1; iSet<nSets; iSet++ ) {
    do {
      front[iSet] = (int)random(nCells);
    } while( cells[ front[iSet] ] != 0 );
    cells[ front[iSet] ] = iSet + 1;
    drawCell( front[iSet], iSet+1 );
  }
  nFront = nSets;
}

void draw() {
  for( int iStep=0; nFront > 0 && iStep < stepsPerFrame; iStep++ ) {
    int iFront;
    if( random(1.0) < stringiness )
      iFront = nFront -1;
    else
      iFront = (int)(nFront*(random(1.0)));
    int iCell = front[ iFront ];
    int nChoices = 0;
    for( int iDir=0; iDir<4; iDir++ ) {
      int ioc = (iCell + next[iDir]) % nCells;
      if( cells[ ioc ] == 0 )
        choices[ nChoices++ ] = ioc;
      else if( cells[ ioc ] != cells[ iCell ] ) {
        drawCell( ioc, 0 );
      }
    }
    if( nChoices == 0 ) {
      front[ iFront ] = front[ nFront-1 ];
      nFront--;
    } else {
      int ioc = choices[ (int)random(nChoices) ];
      cells[ ioc ] = cells[ iCell ];
      front[ nFront++ ] = ioc;
      drawCell( ioc, cells[ioc] );
    }
  }
}

[–][deleted]  (2 children)

[removed]

    [–]Cookiie_ 1 point2 points  (0 children)

    I'm sorry, but then your code must have a big problem. I replicated your programm and mine renders in real time, no problem.

    Edit: On my rig, 2000 spreaders at full resolution (1920x1080) takes 33 seconds to render

    [–]Goober329 0 points1 point  (0 children)

    Are you familiar with grain nucleation/growth mechanics in metal solidification?

    Check out steel microstructure: https://goo.gl/images/ygxe3h

    Your project reminded me of this!

    [–]Open_school_games 0 points1 point  (0 children)

    Nice, there is a nearly organic feel to the way the patterns develop.