Created
November 28, 2012 20:20
-
-
Save automata/4164025 to your computer and use it in GitHub Desktop.
question about matplotlib
This file contains 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
# -*- 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): | |
xs, ys = coords_guy(guy) | |
p.clf() | |
p.axis('off') | |
p.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