Soutrik

network_graphic/Network3

Apr 3rd, 2020
397
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.22 KB | None | 0 0
  1. the idea was to create a moving duplicate of this : https://static.vecteezy.com/system/resources/previews/000/409/336/original/white-neural-network-illustration-vector.jpg
  2.  
  3.  
  4.  
  5. class Network3(Scene):
  6.     def construct(self):
  7.         screen_grid = ScreenGrid()
  8.  
  9.         self.add(screen_grid)
  10.         #function to just random the x and y coordinates
  11.         def randomize_xy():
  12.             for i in range(0,no_of_dots):
  13.                 x_coord[i]=random.randint(-7,+7)
  14.                 y_coord[i]=random.randint(-4,+4)
  15.  
  16.  
  17.             print(x_coord)
  18.             print(y_coord)
  19.         no_of_dots=20
  20.        
  21.         #make some dots
  22.         dots=[]
  23.         for i in range(0,no_of_dots):
  24.             dots.append(Dot())
  25.  
  26.         #make initial list of coordinates
  27.         x_coord=[]
  28.         y_coord=[]
  29.         for i in range(0,no_of_dots):
  30.             x_coord.append(random.randint(-7,7))
  31.             y_coord.append(random.randint(-4,4))
  32.        
  33.  
  34.  
  35.  
  36.        
  37.  
  38.  
  39.         # #make sure all the lengths are ok
  40.         # print(f"length of dots lenght={len(dots)} of x_coord={len(x_coord)}") error of int base 10 is coming from here
  41.         print("length of dots=",end="")
  42.         print(str(len(dots))) #print(len(dots)) still causes an error !!!
  43.  
  44.  
  45.  
  46.         #add all dots at one point
  47.         self.add(*dots)
  48.  
  49.         #make anim list to move everything to their position from origin
  50.         animlist=[]
  51.         for i in range(0,no_of_dots):
  52.             animlist.extend([dots[i].move_to,[x_coord[i],y_coord[i],0]])
  53.  
  54.  
  55.         #play
  56.         self.play(*animlist)
  57.  
  58.         #make a list of value trackers
  59.         x_trackers=[]
  60.         y_trackers=[]
  61.  
  62.         for i in range(0,no_of_dots):
  63.             x_tracker=ValueTracker(x_coord[i])
  64.             y_tracker=ValueTracker(y_coord[i])
  65.  
  66.             x_trackers.append(x_tracker)
  67.             y_trackers.append(y_tracker)
  68.  
  69.         #making lines
  70.         lines=[]
  71.         for i in range(0,no_of_dots-1):
  72.             t1=[x_coord[i],y_coord[i],0]
  73.             t2=[x_coord[i+1],y_coord[i+1],0]
  74.             line=Line(t1,t2)
  75.             lines.append(line)
  76.  
  77.         def update_func1(obj,i):
  78.             temp1=np.array([x_trackers[i],y_trackers[i],0])
  79.             temp2=np.array([x_trackers[i+1],y_trackers[i+1],0])
  80.             line=Line(start=temp1,end=temp2)
  81.             obj.become(line)
  82.  
  83.  
  84.         #making a link between each line and value tracker
  85.         for i in range(0,no_of_dots-1):
  86.             lines[i].add_updater(lambda m:update_func1(m,i))
  87.  
  88.         #adding again
  89.         self.add(*lines)
  90.  
  91.         #making a link between each dot and value tracker
  92.         for i in range(0,no_of_dots):
  93.             dots[i].add_updater(lambda m:m.move_to([x_trackers[i],y_trackers[i],0]))
  94.  
  95.        
  96.         #now somehow have to change all the value tracker at once
  97.         animlist2=[]
  98.         for i in range(0,no_of_dots):
  99.             animlist2.extend([x_trackers[i].set_value,random.randint(-7,+7)])
  100.             animlist2.extend([y_trackers[i].set_value,random.randint(-4,+4)])
  101.  
  102.  
  103.         #now play
  104.         self.play(*animlist2)
  105.  
  106.  
  107.        
  108.         #end
  109.         self.wait(3)
  110.  
  111.  
  112. #########################Current error code is ######################################
  113. Traceback (most recent call last):
  114.   File "C:\manim\manimlib\extract_scene.py", line 155, in main
  115.     scene = SceneClass(**scene_kwargs)
  116.   File "C:\manim\manimlib\scene\scene.py", line 53, in __init__
  117.     self.construct()
  118.   File "network_graphic.py", line 584, in construct
  119.     lines[i].add_updater(lambda m:update_func1(m,i))
  120.   File "C:\manim\manimlib\mobject\mobject.py", line 192, in add_updater
  121.     self.update(0)
  122.   File "C:\manim\manimlib\mobject\mobject.py", line 159, in update
  123.     updater(self)
  124.   File "network_graphic.py", line 584, in <lambda>
  125.     lines[i].add_updater(lambda m:update_func1(m,i))
  126.   File "network_graphic.py", line 578, in update_func1
  127.     line=Line(start=temp1,end=temp2)
  128.   File "C:\manim\manimlib\mobject\geometry.py", line 431, in __init__
  129.     self.set_start_and_end_attrs(start, end)
  130.   File "C:\manim\manimlib\mobject\geometry.py", line 471, in set_start_and_end_attrs
  131.     vect = normalize(rough_end - rough_start)
  132. TypeError: unsupported operand type(s) for -: 'ValueTracker' and 'ValueTracker'
Add Comment
Please, Sign In to add comment