Skip to content

Instantly share code, notes, and snippets.

@thorsummoner
Created June 17, 2016 16:50
Show Gist options
  • Select an option

  • Save thorsummoner/fe4677fbf6915751acc7b24f103fb25c to your computer and use it in GitHub Desktop.

Select an option

Save thorsummoner/fe4677fbf6915751acc7b24f103fb25c to your computer and use it in GitHub Desktop.
Generates noisy png's with python's random functions.
import sys
import png
import random
import itertools
def rand(entries):
for _ in range(entries):
val = random.choice([0, 255])
assert val != 2
yield val
def main():
dimmention = 256
try:
dimmention = sys.argv[2]
except IndexError:
pass
for i in range(int(sys.argv[1])):
image = png.Writer(dimmention, dimmention , greyscale=True)
with open('set{}.png'.format(i), 'wb') as fh:
image.write(fh, [rand(dimmention) for _ in range(dimmention)])
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment