Advertisement
xeromino

lines

Jul 30th, 2014
782
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. ArrayList<Dot> dots;
  2. int num = 7000, d=20, br=180, alpha=40;
  3. int bg=255, s=0;
  4. PImage img;
  5.  
  6. void setup() {
  7. img=loadImage("http://media-cache-ec0.pinimg.com/736x/ca/fd/29/cafd29d721cc0302cee4093ec2e34d27.jpg");
  8. size(img.width, img.height);
  9. background(bg);
  10. dots = new ArrayList<Dot>();
  11. //image(img, 0, 0);
  12. img.loadPixels();
  13. for (int i=0; i<num; i++) {
  14. int x = int(random(width));
  15. int y = int(random(height));
  16. if (brightness(img.pixels[x+y*width])<br) {
  17. dots.add(new Dot(new PVector(x, y)));
  18. }
  19. }
  20. for (Dot d : dots) {
  21. d.lineBetween();
  22. }
  23. }
  24.  
  25. void draw() {}
  26.  
  27. void keyPressed() {
  28. save(random(2332)+".jpg");
  29. }
  30.  
  31. class Dot {
  32.  
  33. PVector loc;
  34.  
  35. Dot(PVector _loc) {
  36. loc = _loc;
  37. }
  38.  
  39. void lineBetween() {
  40. for (int i=0; i<dots.size (); i++) {
  41. Dot other = (Dot) dots.get(i);
  42. float distance = loc.dist(other.loc);
  43. if (distance >0 && distance < d) {
  44. stroke(s, alpha);
  45. line(loc.x, loc.y, other.loc.x, other.loc.y);
  46. }
  47. }
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement