Advertisement
xeromino

filter

Nov 18th, 2014
422
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.50 KB | None | 0 0
  1. PImage img;
  2. void setup() {
  3.   background(220);
  4.   img = loadImage("pic6.jpg");
  5.   size(img.width, img.height);
  6. }
  7. void draw() {
  8.   // let's draw 200 strokes at a time
  9.   for (int i=0; i<200; i++) {
  10.     // calculate the starting point of the stroke
  11.     PVector start = new PVector(random(width), random(height));
  12.  
  13.     // calculate the end point of the stroke
  14.     // 1. the angle of the stroke uses noise values which are calculated based on the starting coordinates of the stroke
  15.     float a = TWO_PI * 2 * noise(map(start.x, 0, width, 0, 4), map(start.y, 0, height, 0, 4));
  16.     // 2. fromAngle calculates and returns a new vector of size 1 from that angle
  17.     PVector end = PVector.fromAngle(a);
  18.     // 3. the length that the stroke will have
  19.     float len = random(3, 10);
  20.     // 4. that length is added to the end point of the stroke
  21.     end.mult(len);
  22.     // 5. the end point is added to the starting point in order to get its actual coordinates on the screen
  23.     end.add(start);
  24.  
  25.     // calculate color
  26.     // not really necessary here: PVector pointInImage = new PVector(map(start.x, 0, width, 0, img.width), map(start.y, 0, height, 0, img.height));
  27.     // not really necessary here: color c = img.get((int)pointInImage.x, (int)pointInImage.y);
  28.     color c = img.get(int(start.x), int(start.y));
  29.  
  30.     // draw
  31.     stroke(c,50);
  32.     strokeWeight(random(2, 6));
  33.     // the stroke is being painted
  34.     line(start.x, start.y, end.x, end.y);
  35.   }
  36. }
  37.  
  38. void keyPressed() {
  39.   save(random(233555)+".jpg");
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement