Chaosboxen

RobertIbisch

Dies ist die Weiterführung der Buchstaben und basiert eben so auf:

“Scattered Letters by Algirdas Rascius. http://openprocessing.org/visuals/?visualID=1811

 

/**
 * Scattered Letters
 * by Algirdas Rascius.
 * http://openprocessing.org/visuals/?visualID=1811
 * modified by Robert Ibisch
 *  
 * Click to restart.
 */  

PFont font;
float currentSize;
  String[] words = { "P", "a", "u", "l", "K", "l", "e", "e"};
  int index = int(random(words.length));

void setup() {
  size(640, 480);
  colorMode(HSB, TWO_PI, 1, 1, 1); 

      //font = loadFont("BookmanOldStyle-Bold-48.vlw");
      smooth();
  initialize();
} 

void draw() { 

  if (currentSize > 10) {
    if (!randomLetter(currentSize)) {
      currentSize = currentSize*0.99; 

    }
  }
} 

void initialize() {
  background(color(0, 0, 1));
  currentSize = 300;
} 

void mouseClicked() {
   initialize();
} 

void keyPressed() {
   initialize();
} 

boolean randomLetter(float letterSize) {
  int intSize = (int)letterSize; 

  PGraphics g = createGraphics(intSize, intSize, JAVA2D);
  g.beginDraw();
  g.background(color(0, 0, 1, 0));
  //g.fill(color(0, 0, 0));
 // g.textAlign(CENTER, CENTER);
  g.rectMode(CENTER);
  g.translate(letterSize/2, letterSize/2);
   g.rotate(random(TWO_PI));
  g.scale(letterSize/300);
 // g.textFont(font);
  g.fill(random(150),random(175),random(125),random(100));
  g.noStroke();
  g.rect(0,0,mouseX/2,mouseY/2);
//   int i =int ( random(8)) ;
// g.text(words[i], 0, 0);

  g.endDraw(); 

  PGraphics gMask = createGraphics(intSize, intSize, P2D);
  gMask.beginDraw();
  gMask.background(color(0, 0, 1, 1));
  gMask.image(g, 0, 0);
  gMask.filter(ERODE);
  gMask.filter(ERODE);
  gMask.endDraw(); 

  for (int tries=50; tries>0; tries--) { 

    int x1 = (int)random(width-intSize);
    int y1 = (int)random(height-intSize); 

     int x = x1/4 + mouseX;
     int y = y1/4 + mouseY;

    boolean fits = true;
    for (int dx = 0; dx<intSize && fits; dx++) {
      for (int dy = 0; dy<intSize && fits; dy++) {
        if (brightness(gMask.get(dx, dy))<0.5) {
          if (brightness(get(x+dx, y+dy))<0.5) {
            fits = false;
          }
        }
      }
    }
    if (fits) {
      image(g, x, y);
      return true;
    }
  }
  return false;
}