Skip to content

Instantly share code, notes, and snippets.

@timothy-allan
Created September 3, 2019 11:07
Show Gist options
  • Save timothy-allan/0f67dc85f2dfcb81fbaf0d9859e4101e to your computer and use it in GitHub Desktop.
Save timothy-allan/0f67dc85f2dfcb81fbaf0d9859e4101e to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Jul 9 09:17:05 2019
'''
from PIL import Image, ImageDraw
import random
#im = Image.open('/Users/timallan/Desktop/whiteFang/01_ASSETS/__IMAGES/_DL/northernLights_1920x1080.png')
im = Image.new('RGB', (200, 200), (240, 240, 240))
w, h = im.size
pixelTotal = w * h
pixelTarget = int(pixelTotal * 0.41)
pointsDrawn = 0
pointsDrawnList = []
x = random.randrange(w)
y = random.randrange(h)
steps = 0
draw = ImageDraw.Draw(im)
while pointsDrawn < pixelTarget:
steps += 1
if (x, y) not in pointsDrawnList:
draw.point((x, y), (5, 5, 5))
pointsDrawnList.append((x, y))
pointsDrawn +=1
stepx = random.randrange(-1, 2)
stepy = random.randrange(-1, 2)
x += stepx
y += stepy
if x < 0 or x > w: x = 0
if y < 0 or y > h: y = 0
del draw
im.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment