Skip to content

Instantly share code, notes, and snippets.

@jaddoescad
Created March 10, 2019 18:55
Show Gist options
  • Save jaddoescad/738f21518597780b1040f24a0f13cca7 to your computer and use it in GitHub Desktop.
Save jaddoescad/738f21518597780b1040f24a0f13cca7 to your computer and use it in GitHub Desktop.
Create Vector Field
from big_ol_pile_of_manim_imports import *
class SimpleField(Scene):
CONFIG = {
"plane_kwargs" : {
"color" : RED}}
def construct(self):
plane = NumberPlane(**self.plane_kwargs) #Create axes and grid
plane.add(plane.get_axis_labels()) #add x and y label
self.add(plane) #Place grid on screen
points = [x*RIGHT+y*UP
for x in np.arange(-5,5,1)
for y in np.arange(-5,5,1)
] #List of vectors pointing to each grid point
vec_field = [] #Empty list to use in for loop
for point in points:
field = 0.5*RIGHT + 0.5*UP #Constant field up and to right
result = Vector(field).shift(point) #Create vector and shift it to grid point
vec_field.append(result) #Append to list
draw_field = VGroup(*vec_field) #Pass list of vectors to create a VGroup
self.play(ShowCreation(draw_field)) #Draw VGroup on screen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment