Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PImage img;
- void setup() {
- background(220);
- img = loadImage("pic6.jpg");
- size(img.width, img.height);
- }
- void draw() {
- // let's draw 200 strokes at a time
- for (int i=0; i<200; i++) {
- // calculate the starting point of the stroke
- PVector start = new PVector(random(width), random(height));
- // calculate the end point of the stroke
- // 1. the angle of the stroke uses noise values which are calculated based on the starting coordinates of the stroke
- float a = TWO_PI * 2 * noise(map(start.x, 0, width, 0, 4), map(start.y, 0, height, 0, 4));
- // 2. fromAngle calculates and returns a new vector of size 1 from that angle
- PVector end = PVector.fromAngle(a);
- // 3. the length that the stroke will have
- float len = random(3, 10);
- // 4. that length is added to the end point of the stroke
- end.mult(len);
- // 5. the end point is added to the starting point in order to get its actual coordinates on the screen
- end.add(start);
- // calculate color
- // not really necessary here: PVector pointInImage = new PVector(map(start.x, 0, width, 0, img.width), map(start.y, 0, height, 0, img.height));
- // not really necessary here: color c = img.get((int)pointInImage.x, (int)pointInImage.y);
- color c = img.get(int(start.x), int(start.y));
- // draw
- stroke(c,50);
- strokeWeight(random(2, 6));
- // the stroke is being painted
- line(start.x, start.y, end.x, end.y);
- }
- }
- void keyPressed() {
- save(random(233555)+".jpg");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement