Avoid intersection

Im pretty lost in this issue.

I have a program that generates a chain of lines but I need to avoid intersections like these:

Screen Shot 2016-04-19 at 5.01.56 PM

Any idea of where should I start?

Here is the code:

String original = "STELLAR";
String[] splited = original.split(" ");
char[] letters;

PFont myFont;

void setup() 
{
  frameRate(1);
  size(500, 300);
  pixelDensity(displayDensity());


  myFont = createFont("MaisonNeue-Bold", 15);
  fill(15);
  textFont(myFont);
  textAlign(CENTER, CENTER);

}

void draw()
{

  background(255);
  for(int s=0; s< splited.length; s++)
  {  
    letters = splited[s].toCharArray();  
  }  

  int xPos[]=new int [letters.length];
  int yPos[]=new int [letters.length];

  for (int i = 0; i<letters.length; i++) 
  {  
    xPos[i]= (int) random(width/5, width - width/5);
    yPos[i]= (int) random(height/5, height - height/5);
    text(letters[i], xPos[i], yPos[i] );

    if (i>0)
    {       
      stroke(0);
      strokeWeight(2);
      float sx = lerp(xPos[i-1], xPos[i], .1 );
      float ex = lerp(xPos[i-1], xPos[i], .9 );
      float sy = lerp(yPos[i-1], yPos[i], .1 );
      float ey = lerp(yPos[i-1], yPos[i], .9 );
      line(sx, sy, ex, ey);
    }
  }     
}
Tagged:
Sign In or Register to comment.