2021年3月26日星期五

Function did not get called in FuncAnimation?

from matplotlib import *  import matplotlib.pyplot as plt  import random  from matplotlib.animation import FuncAnimation  import tkinter as tk   import numpy as np    def boxPlot(length, width):      x=list()      y=list()      # Initializing 10x10 tiles of size 0.1sq.units.      for num in range(1, int(round(length/0.1, 0)+1)):          x.append(round(num*0.1, 2))      for num in range(1, int(round(width/0.1, 0)+1)):              y.append(round(num*0.1, 2))      plt.grid()      plt.xlim(xmin=0, xmax=1*length*10)      plt.ylim(ymin=0, ymax=1*width*10)      plt.xticks(np.arange(1, (length+0.1)*10, 1),x)      plt.yticks(np.arange(1, (width+0.1)*10, 1),y)      return length, width        def updateGrid(box):      a = box[0][0]      b = box[0][1]      count = 0      particularBox_xCoord = [(b-1)*1, (b-1)*1,(b)*1, (b)*1,(b-1)*1 ]      particularBox_yCoord = [(a-1)*1, (a)*1,(a)*1, (a-1)*1, (a-1)*1]      plt.plot(particularBox_xCoord, particularBox_yCoord,'blue')      count = count + 1      return plt.plot(particularBox_xCoord, particularBox_yCoord,'blue'),              def generatorFunc(length, width):      done_list = []      while len(done_list) < length*width*100:          a = random.randint(1,int(length*10)) # row number          b = random.randint(1,int(width*10))# column number          if [a, b] not in done_list:                        done_list.append([a, b])      return done_list    def main():      fig1 = plt.figure()      done_list = []      plt.ion()       length = float(input('Please enter the length of the room in 10 tiles(0, 10): '))      width = float(input('Please enter the width of the room in 10 tiles(0, 10): '))           length, width = boxPlot(length, width)      done_list = generatorFunc(length, width)      # box number to colour    # =============================================================================  #     while len(done_list) < length*width*100:  #         a = random.randint(1,int(length*10)) # row number  #         b = random.randint(1,int(width*10))# column number  #         if [a, b] not in done_list:            #             done_list.append([a, b])  #         #updateGrid(done_list)  # =============================================================================      ani = FuncAnimation(fig1, updateGrid,  done_list, interval=1000)      #updateGrid(done_list[-1][0],done_list[-1][1])         plt.show()     main()                

I am doing a project for a bot cleaning room. I use the generator function to generate the random spots for finished cleaning and I want to show the progress in an animation. I doubt if the updateGrid function gets called. I looked at the documentation and did not fully understand the details. should I return something from the updateGrid function? What is wrong with my code? Thanks million!

https://stackoverflow.com/questions/66828176/function-did-not-get-called-in-funcanimation March 27, 2021 at 01:05PM

没有评论:

发表评论