Jordan Parsons
- Second Year Architect

Processing – Line Generator

Posted By: Jordan Parsons

I just started working with Processing, and have developed a few basic applications. This one is really simple but its kinda fun in a geeky sort of way. The basic premise is that is uses user input of the size of the window to generate random lines of increasing white levels that then cycles back to black.

http://jordanparsons.com/processing/line_generator_2_12_08/

Line Generator

Source Code:

import processing.pdf.*;
import processing.opengl.*;

int lc = 0; //line color
String pdfName = "Lines";
int imgSize = 500; //window size (square)
int delayDraw = 0; //delay between lines
int colorUp = 20; //amount the color steps each pass
boolean saveOneFrame = false;
void setup(){
  size(500,500,OPENGL);
  background(255);
  frameRate(30);
  //beginRecord(PDF, pdfName + ".pdf");
  //println("Click to End Recording & output PDF.");
}
void draw(){
  noLoop();
    for(int i=0; i < 10; i = i + 1){
     // if(saveOneFrame == true) {
      //  endRecord();
      //  println("PDF Saved as " + pdfName + ".pdf");
      //  saveOneFrame = false;
      //  exit();
      //}
      float x = random(0,imgSize);
      float y = random(0,imgSize);
      pushMatrix();
      stroke(lc);
      line(0,x,y,0);
      line(0,0,x,y);
      line(imgSize,x,y,imgSize);
      line(imgSize,imgSize,x,y);
      popMatrix();
      delay(delayDraw);
      lc=lc+colorUp;
      if(lc>255) lc=0;
     }

}

void keyPressed(){
  if(key == ' '){
      redraw();
  }
}

void mousePressed() {
  saveOneFrame = true;
   redraw();
}

The lines that have been commented out, when turned back on will save the lines as a .pdf which is pretty handy. I plan to use this for a project I am working on as a wall piece. Feel free to edit the source and play around with it. Here is a link to a demo, no save version.

http://jordanparsons.com/processing/line_generator_2_12_08/

p1 p1 p1 



No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment



© 2009 Jordan Parsons
Grab the feed