Skip to content

Instantly share code, notes, and snippets.

@automata
Created November 29, 2012 19:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save automata/4171341 to your computer and use it in GitHub Desktop.
Save automata/4171341 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
import numpy as n
import random as r
import pylab as p
DIRS = ['up', 'right', 'down', 'left']
def new_guy():
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()
plot = fig.add_subplot(111)
xs, ys = coords_guy(guy)
plot.clear()
plot.axis('off')
plot.set_clip_on(False)
artists = []
artists.extend(plot.collections)
artists.extend(plot.patches)
artists.extend(plot.lines)
artists.extend(plot.texts)
artists.extend(plot.artists)
for a in artists:
a.set_clip_on(False)
plot.plot(xs, ys, 'k-')
p.savefig('guy.png')
guy_to_fig(new_guy())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment