from k3d import K3D
from math import sin, cos, pi
width = height = 20
view_matrix = (
7.0, 5.0, -5.0, 0.0,
0.0, 7.0, 7.0, 5.0,
7.0, -5.0, 5.0, 0.0,
0.0, 0.0, 0.0, 1.0
)
def f(x, y):
return sin(float(x) / width * pi * 2.0), cos(float(y) / height * pi * 2.0)
colors = [0xFF0000, 0xFFFFFF] * width * height
vectors = [[f(x, y) for x in range(width)] for y in range(height)]
plot = K3D(background_color=0)
plot += K3D.vectors_fields(vectors, colors, view_matrix=view_matrix, use_head=False)
plot.display()