-
-
Save pierre-haessig/4203760 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as n | |
import random as r | |
import pylab as p | |
DIRS = ['up', 'right', 'down', 'left'] | |
def new_guy(seed=0): | |
r.seed(seed) | |
dna = [[r.choice(DIRS), | |
r.randint(1, 40), | |
1] for i in xrange(20)] | |
return dna | |
def coords_guy(guy): | |
x = 0 | |
y = 0 | |
xs = [0] | |
ys = [0] | |
for instr in guy: | |
if instr[0] is 'up': | |
y += instr[1] * instr[2] | |
elif instr[0] is 'down': | |
y -= instr[1] * instr[2] | |
elif instr[0] is 'right': | |
x += instr[1] * instr[2] | |
elif instr[0] is 'left': | |
print 'hey' | |
x -= instr[1] * instr[2] | |
xs.append(x) | |
ys.append(y) | |
return (xs, ys) | |
def guy_to_fig(guy): | |
fig = p.figure() | |
ax = fig.add_subplot(111) | |
xs, ys = coords_guy(guy) | |
ax.clear() | |
ax.axis('off') | |
l, = ax.plot(xs, ys, 'k-') | |
l.set_clip_on(False) | |
p.savefig('guy.png') | |
#p.show() | |
guy_to_fig(new_guy(0)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment