Vector field graph plotter


(graphic program)



# INSTRUCTIONS: In order to input your vector field, you need to edit the "nx" and "ny" parameters (lines 52, 53) directly inside the code.

from math import *
from random import *
from tkinter import *
#from transcol import *

#this is the "transcol" module, please put it in the right directory:
def rgb(r,g,b):
     hr=list(hex(int(r)))
     hg=list(hex(int(g)))
     hb=list(hex(int(b)))
     hr.remove("0")
     hr.remove("x")
     hg.remove("0")
     hg.remove("x")
     hb.remove("0")
     hb.remove("x")
     if len(hr)<2:
          hr.insert(0,"0")
     if len(hg)<2:
          hg.insert(0,"0")
     if len(hb)<2:
          hb.insert(0,"0")
     return "#"+"".join(hr)+"".join(hg)+"".join(hb)

wx=800
wy=800
w=Tk()
a=Canvas(w,width=wx,height=wy,bg=rgb(0,0,0))
a.pack()
h=1/1000
zoom=20
nts=0.1
res=1

for xa in range(0,400,zoom):
    a.create_line(400-xa,0,400-xa,800,fill=rgb(64,64,64))
    a.create_line(400+xa,0,400+xa,800,fill=rgb(64,64,64))
for ya in range(0,400,zoom):
    a.create_line(0,400-ya,800,400-ya,fill=rgb(64,64,64))
    a.create_line(0,400+ya,800,400+ya,fill=rgb(64,64,64))
a.create_line(400,0,400,800,fill=rgb(128,128,128))
a.create_line(0,400,800,400,fill=rgb(128,128,128))
a.update()

y=-400
while y<400:
    x=-400
    while x<400:
        
        nx=x
        ny=y
        
        a.create_line(400+(x*zoom),400+(y*zoom),400+(x*zoom)+(nx*zoom*nts),400+(y*zoom)+(ny*zoom*nts),fill=rgb(255,255,255))
        a.create_oval(400+(x*zoom)+(nx*zoom*nts),400+(y*zoom)+(ny*zoom*nts),400+(x*zoom)+(nx*zoom*nts)+2,400+(y*zoom)+(ny*zoom*nts)+2,outline="",fill=rgb(255,255,255))
        x=x+(1/res)
    y=y+(1/res)

a.update()
a.mainloop()
	
	

Return