#random chain polymer, fixed turning angle
from __future__ import division, print_function
from visual import *
from visual.graph import *
from random import random
import numpy as np
#inputs
N=500
repeat=10
theta=pi/4.
#setup
r=zeros((N,2))
R=array([[cos(theta),sin(theta)],[-sin(theta),cos(theta)]])
L=array([[cos(theta),-sin(theta)],[sin(theta),cos(theta)]])
A=R
d=array([1,0])
track=curve(color=color.yellow)
track.append(pos=r[0,:])
#generate tracks
for rep in arange(repeat):
    rate(10)
    for i in arange(1,N):
        u=random()
        A=R
        if u <0.5 : A=L
        d=np.dot(A,d)
        r[i,:]=r[i-1,:]+d
        track.append(pos=r[i,:])
