Skip to content

Instantly share code, notes, and snippets.

@pierre-haessig
Forked from automata/qplot2.py
Created December 4, 2012 13:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pierre-haessig/4203760 to your computer and use it in GitHub Desktop.
Save pierre-haessig/4203760 to your computer and use it in GitHub Desktop.
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