Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. FG = color(17, 17, 17, 10) # foreground color
  2. BG = "#f3f3f3" # background color
  3.  
  4. WIDTH = 1000
  5. ASPECT_RATIO = 0.666 # !!! copy from console
  6.  
  7. TOTAL_FRAMES = 10 # higher means darker & covering higher percentage of picture
  8.  
  9. LINE_LENGTH = 65 # higher means more blurry & darker
  10. GRID_DISTANCE = 15 # if GRID_DISTANCE >> LINE_LENGTH, picture may be incomplete; higher -> lighter
  11. MAX_LINES_PER_STAR = 50 # higher means higher sensitivity (more shades), darker with less visible stars,
  12. # should be typically >> GRID_DISTANCE
  13. LINE_LENGTH_RATIO_DARK = 0.5 # how much shorter (relatively) should be the lines for darkest areas
  14.  
  15. X_SHIFT = 3 # to prevent a boring rectangular grid
  16. Y_SHIFT = 4
  17.  
  18. def setup():
  19. global img
  20.  
  21. img = loadImage("picture.jpg") # !!! this file needs to be in the sketch folder
  22. aspect_ratio = float(img.height) / float(img.width)
  23. println("Aspect ratio: " + str(aspect_ratio))
  24. img.resize(WIDTH, int(WIDTH * aspect_ratio))
  25.  
  26. size(WIDTH, int(WIDTH * ASPECT_RATIO))
  27. background(BG)
  28. stroke(FG)
  29.  
  30.  
  31. def draw():
  32. if frameCount <= TOTAL_FRAMES:
  33. for x in range((frameCount * X_SHIFT) % GRID_DISTANCE, img.width, GRID_DISTANCE):
  34. for y in range((frameCount * Y_SHIFT) % GRID_DISTANCE,
  35. img.height, GRID_DISTANCE):
  36. c = img.get(x, y)
  37. b = map(brightness(c), 0, 255, 1, 0)
  38. for i in range(int(b * MAX_LINES_PER_STAR)):
  39. random_line(x, y, LINE_LENGTH * (1 - LINE_LENGTH_RATIO_DARK))
  40.  
  41.  
  42. def random_line(x, y, w):
  43. pushMatrix()
  44. translate(x, y)
  45. rotate(random(0, TWO_PI))
  46. line(-w/2, 0, w/2, 0)
  47. popMatrix()
  48.  
  49. def keyPressed():
  50. if key == 's':
  51. saveFrame("frame-######.png")
  52. println("Frame saved")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement