Kara walks from left to right and from right to left, alternatively, and "inverts" the current row of the image. The main program is the following:
walkingLeft2Right = 1
while not (kara.treeFront() and (kara.treeLeft() or kara.treeRight())):
if walkingLeft2Right:
left2right()
else:
right2left()
walkingLeft2Right = not walkingLeft2Right