Advertisement
skaramicke

Untitled

Nov 13th, 2015
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.58 KB | None | 0 0
  1. width = 4096
  2. height = 2304
  3. thickness = 3
  4. glow = 15
  5. iterations = 20
  6. depth = 5
  7.  
  8. from sys import stdout
  9. from PIL import Image, ImageDraw
  10. from math import sin, pi, hypot, log
  11.  
  12. #used for relative opacity later
  13. maxdecay = hypot(0, glow)
  14.  
  15. image = Image.new('RGB', (width, height), (0, 0, 0, 0))
  16. draw = ImageDraw.Draw(image, 'RGBA')
  17.  
  18. def drawPixel(x, y, opacityFactor):
  19.     for x_offset in range(0-glow, glow):
  20.         for y_offset in range(0-glow, glow):
  21.             distance = hypot(x_offset, y_offset)
  22.             if distance <= thickness/2:
  23.                 opacity = 255
  24.             else:
  25.                 if distance > maxdecay:
  26.                     opacity = 0
  27.                 else:
  28.                     opacity = 255 - 255 / maxdecay * distance;
  29.                     if (opacity > 0):
  30.                         opacity = log(opacity)/2
  31.             opacity = int(round(float(opacity) * float(opacityFactor)))
  32.             draw.point( (x + x_offset, y + y_offset), fill=(255, 255, 255, opacity))
  33.  
  34. for j in range(0, iterations):
  35.     for z in range(0, depth):
  36.         for x in range(width):
  37.             y = int((height/2) + (height/2.2-40*j) * sin(2.0*pi*x/width))
  38.             drawPixel(x, y, z/float(depth))
  39.  
  40.             total = float(iterations) * float(depth) * float(width)
  41.             current = float(j)*float(width) + float(z)*float(width) + float(x)
  42.            
  43.             progress = current / total * 100.0
  44.             stdout.write("\r%s" % round(progress, 2)+'% complete. ' + str(round(z/float(depth), 2)))
  45.             stdout.flush()
  46.  
  47. stdout.write("\n")
  48. image.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement