SHARE
TWEET

Untitled

a guest Jul 22nd, 2019 321 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. """
  4. Created on Tue Jul  9 09:17:05 2019
  5.  
  6. @author: timallan
  7. """
  8.  
  9.  
  10. from PIL import Image, ImageDraw
  11. import random
  12.  
  13. #im = Image.open('/Users/timallan/Desktop/whiteFang/01_ASSETS/__IMAGES/_DL/northernLights_1920x1080.png')
  14.  
  15. im = Image.new('RGB', (1920, 1080), ('black'))
  16.  
  17. w, h = im.size
  18.  
  19. pixelTotal = w * h
  20. pixelTarget = int(pixelTotal * .41)
  21.  
  22. pointsDrawn = 0
  23. pointsDrawnList = []
  24.  
  25. x = random.randrange(w)
  26. y = random.randrange(h)
  27.  
  28. draw = ImageDraw.Draw(im)
  29.  
  30.  
  31. for points in range(pixelTarget):
  32.     choice = random.randrange(4)
  33.    
  34.     if x < 0 or x > w:
  35.             x = 0
  36.     if y < 0 or y > h:
  37.             y = 0
  38.            
  39.     if choice == 0:
  40.         x += 1
  41.         draw.point((x, y), fill = ('white'))
  42.         pointsDrawnList.append(y)
  43.         pointsDrawnList.append(x)
  44.        
  45.     elif choice == 1:
  46.         x -= 1
  47.         draw.point((x, y), fill = ('white'))
  48.         pointsDrawnList.append(y)
  49.         pointsDrawnList.append(x)
  50.        
  51.     elif choice == 2:
  52.         y += 1
  53.         draw.point((x, y), fill = ('white'))
  54.         pointsDrawnList.append(y)
  55.         pointsDrawnList.append(x)
  56.    
  57.     elif choice == 3:
  58.         y -= 1
  59.         draw.point((x, y), fill = ('white'))
  60.         pointsDrawnList.append(y)
  61.         pointsDrawnList.append(x)
  62.        
  63. del draw
  64. print( len(pointsDrawnList) / 2 )
  65.  
  66. im.save('/Users/timallan/Desktop/whiteFang/05_CODE/PYTHON/_GENERATED_IMAGES/1920x1080_random_walk_06.png', 'PNG')          
  67. im.show()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top