0

Is there a method using numpy and matplotlib to move a unit forward when there's a 1 and rotate by 45 degrees when there's a 0? Based on the array, [0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1] create a graph starting from the coordinate (0, 0) and move ahead by one unit if there's a 1 and rotate by 45 degrees if you encounter 0.

I attempted this on a small scale but have got to nowhere.

from math import sin, cos, radians

def parse(lexemes):
    current = [0, 0]
    path = [current] 
    angle = 0  # In degrees
    for lex in lexemes:
        if not lex:
            angle += radians(45) 
        else:
            current[0] += cos(angle)
            current[1] += sin(angle)
            path.append(current)
    return path

print(parse([0, 1, 1, 0, 1]))
  • I guess the elements of the `path` you get are the same. Please refer to [How do I clone a list so that it doesn't change unexpectedly after assignment?](https://stackoverflow.com/questions/2612802/how-do-i-clone-a-list-so-that-it-doesnt-change-unexpectedly-after-assignment) – Mechanic Pig Oct 09 '22 at 09:46

0 Answers0