title: Snake animation
body: <p>I got a homework for my coding class and im not sure how to do it. I am supposed to make an animation that would light up the squares in a sort of snake type animation (it starts in top left square, continues to top right, then goes to second line but instead of starting on right side, it starts on left side). How should I do it? Please help me, I'm clueless. Below is the code I've got so far.</p>
  
  <pre><code>import tkinter as tk
  import random
  
  
  master = tk.Tk()
  rectangle_list = []
  canvas_width = 280
  canvas_height = 250
  w = tk.Canvas(master, width=canvas_width, height=canvas_height)
  w.pack()
  input1 = tk.Entry (master)
  w.create_window(100, 40, window=input1)
  
  for i in range(11):
      x = i * 25
      if i == 1:
          rectangle_list.append(w.create_rectangle(0, 0, 25, 25, fill="grey"))
      else:
          rectangle_list.append(w.create_rectangle(x-25, 0, x, 25, fill="grey"))
  
  for i in range(11):
      x = i * 25
      if i == 1:
          rectangle_list.append(w.create_rectangle(0, 25, 25, 50, fill="grey"))
      else:
          rectangle_list.append(w.create_rectangle(x-25, 25, x, 50, fill="grey"))
  
  for i in range(11):
      x = i * 25
      if i == 1:
          rectangle_list.append(w.create_rectangle(0, 50, 25, 75, fill="grey"))
      else:
          rectangle_list.append(w.create_rectangle(x-25, 50, x, 75, fill="grey"))
  
  for i in range(11):
      x = i * 25
      if i == 1:
          rectangle_list.append(w.create_rectangle(0, 75, 25, 100, fill="grey"))
      else:
          rectangle_list.append(w.create_rectangle(x-25, 75, x, 100, fill="grey"))
  
  for i in range(11):
      x = i * 25
      if i == 1:
          rectangle_list.append(w.create_rectangle(0, 100, 25, 125, fill="grey"))
      else:
          rectangle_list.append(w.create_rectangle(x-25, 100, x, 125, fill="grey"))
  
  for i in range(11):
      x = i * 25
      if i == 1:
          rectangle_list.append(w.create_rectangle(0, 125, 25, 150, fill="grey"))
      else:
          rectangle_list.append(w.create_rectangle(x-25, 125, x, 150, fill="grey"))
  
  for i in range(11):
      x = i * 25
      if i == 1:
          rectangle_list.append(w.create_rectangle(0, 150, 25, 175, fill="grey"))
      else:
          rectangle_list.append(w.create_rectangle(x-25, 150, x, 175, fill="grey"))
  
  for i in range(11):
      x = i * 25
      if i == 1:
          rectangle_list.append(w.create_rectangle(0, 175, 25, 200, fill="grey"))
      else:
          rectangle_list.append(w.create_rectangle(x-25, 175, x, 200, fill="grey"))
  
  for i in range(11):
      x = i * 25
      if i == 1:
          rectangle_list.append(w.create_rectangle(0, 200, 25, 225, fill="grey"))
      else:
          rectangle_list.append(w.create_rectangle(x-25, 200, x, 225, fill="grey"))
  
  for i in range(11):
      x = i * 25
      if i == 1:
          rectangle_list.append(w.create_rectangle(0, 225, 25, 250, fill="grey"))
      else:
          rectangle_list.append(w.create_rectangle(x-25, 225, x, 250, fill="grey"))
  
  # manage color change loop based on index of rectangle list
  def uno(ndex=0):
      if ndex &lt; len(rectangle_list):
          w.itemconfig(rectangle_list[ndex], fill='red')
          master.after(100, uno, ndex+1)
  
  
  def dos(ndex=0):
      if ndex &lt; len(rectangle_list):
          w.itemconfig(rectangle_list[ndex], fill='grey')
          master.after(0, dos, ndex+1)
  
  def tres(ndex=0):
      if ndex &lt; len(rectangle_list):
          w.itemconfig(rectangle_list[ndex], fill='red')
          master.after(100, tres, ndex-1)
  
  def quatros(ndex=0):
      if ndex &lt; len(rectangle_list):
         w.itemconfig(rectangle_list[ndex], fill='red')
         master.after(100, tres, ndex-6)
      if ndex &lt; len(rectangle_list):
          w.itemconfig(rectangle_list[ndex], fill='red')
          master.after(100, uno, ndex+6)
  
  def cinq(ndex=0):
      if ndex &lt; len(rectangle_list):
         w.itemconfig(rectangle_list[ndex], fill='red')
         master.after(100, tres, ndex-1)
      if ndex &lt; len(rectangle_list):
          w.itemconfig(rectangle_list[ndex], fill='red')
          master.after(100, uno, ndex+1)
  
  def six(ndex=0):
      while True:
          if ndex == len(rectangle_list):
              w.itemconfig(rectangle_list[ndex], fill='red')
              master.after(10, six, ndex+random.choice(rectangle_list))
  
  def seven(ndex=0):
      if ndex &lt; len(rectangle_list):
          w.itemconfig(rectangle_list[ndex], fill='red')
          master.after(100, seven, ndex+3)
  
  tk.Button(master, text="animacia", command=uno).pack(side='left', padx=10)
  tk.Button(master, text="zhasni", command=dos).pack(side='left', padx=10)
  tk.Button(master, text="animacia 2", command=tres).pack(side='left', padx=10)
  tk.Button(master, text="animacia 3", command=quatros).pack(side='left', padx=10)
  tk.Button(master, text="animacia 4", command=cinq).pack(side='left', padx=10)
  tk.Button(master, text="animacia 5", command=six).pack(side='left', padx=10)
  tk.Button(master, text="animacia 6", command=seven).pack(side='left', padx=10)
  master.mainloop()
  </code></pre>