Skip to content

Instantly share code, notes, and snippets.

@pocket7878
Created November 26, 2015 05:37
Show Gist options
  • Save pocket7878/d25499f024d3f8c21304 to your computer and use it in GitHub Desktop.
Save pocket7878/d25499f024d3f8c21304 to your computer and use it in GitHub Desktop.
# coding: utf-8
# In[5]:
from PIL import Image, ImageDraw
from matplotlib.pyplot import imshow
import numpy as np
import random
# In[6]:
get_ipython().magic(u'matplotlib inline')
# In[7]:
import noise
# In[8]:
def getNoiseSequence(width, padding=0.0, amp=1.0):
a = random.uniform(0,0.1)
return [int((noise.pnoise1(a*i) * amp) + padding) for i in xrange(width)]
# In[20]:
def createImage(width, height, bgColor=(255,255,255)):
return Image.new('RGB', (width, height), bgColor)
# In[21]:
image = createImage(256, 256)
# In[22]:
def insertNoise(image, color, padding=0.0, amp=1.0):
w = image.width
noiseSeq = getNoiseSequence(w, padding, amp)
draw = ImageDraw.Draw(image)
for x in range(0, w):
n = noiseSeq[x]
draw.line((x, 0, x, n), color)
del draw
image
# In[23]:
def insertNoises(image, color1, color2):
h = image.height
h -= 20
flg = 1
while True:
if (h > 10):
if (flg == 1):
insertNoise(image, color1, padding=h, amp=10)
flg = 0
else:
insertNoise(image, color2, padding=h, amp=10)
flg = 1
h -= 20
else:
break
return image
# In[24]:
def genCurtain(width, height, color1, color2):
image = createImage(width, height, bgColor=color1)
insertNoises(image, color1, color2)
return image
# In[25]:
genCurtain(256, 256, (242, 202, 170), (166, 82, 63))
# In[ ]:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment