"""Plot the electric field generated by three point charges in a plane."""

import numpy as np
import pylab as plt

import vectorplot as vp

dpi = 100
size = 700
video = False

# Charges : (q, x, y)
charges = [(10, +0.5, +0.5), (-10, -0.5, -0.5), (4, +0.2, -0.2)]

xs = np.linspace(-1, 1, size).astype(np.float32)[None, :]
ys = np.linspace(-1, 1, size).astype(np.float32)[:, None]

u = np.zeros((size, size), dtype=np.float32)
v = np.zeros((size, size), dtype=np.float32)

for (q, x, y) in charges:
    rsq = ((xs-x)**2+(ys-y)**2)**1.5
    v += -q * (ys-y)/rsq
    u += -q * (xs-x)/rsq

texture = np.random.rand(size, size).astype(np.float32)

plt.bone()
frame = 0

if video:
    kernellen = 62
    steps = 125
    turns = 3
    for t in np.linspace(0, turns, steps, endpoint=False):
        kernel = vp.kernels.hanning_ripples(N=kernellen, shift=t)

        kernel = kernel.astype(np.float32)

        image = vp.line_integral_convolution(u, v, texture, kernel)

        plt.clf()
        plt.axis('off')
        plt.figimage(image)
        plt.gcf().set_size_inches((size/float(dpi), size/float(dpi)))
        plt.savefig("efield-%04d.png" % frame, dpi=dpi)
        frame += 1
else:
    kernellen = 31
    kernel = np.sin(np.arange(kernellen)*np.pi/kernellen)
    kernel = kernel.astype(np.float32)
    print(u.dtype, v.dtype, texture.dtype, kernel.dtype)
    print(u.shape, v.shape, texture.shape, kernel.shape)

    image = vp.line_integral_convolution(u, v, texture, kernel)

    plt.clf()
    plt.axis('off')
    plt.figimage(image)
    plt.gcf().set_size_inches((size/float(dpi), size/float(dpi)))
    plt.savefig("efield-image.png", dpi=dpi)

9c5724a28e4af1264f732b5c3ae5943f5fd05e15
<mask token>

<mask token>
for q, x, y in charges:
    rsq = ((xs - x) ** 2 + (ys - y) ** 2) ** 1.5
    v += -q * (ys - y) / rsq
    u += -q * (xs - x) / rsq
<mask token>
plt.bone()
<mask token>
if video:
    kernellen = 62
    steps = 125
    turns = 3
    for t in np.linspace(0, turns, steps, endpoint=False):
        kernel = vp.kernels.hanning_ripples(N=kernellen, shift=t)
        kernel = kernel.astype(np.float32)
        image = vp.line_integral_convolution(u, v, texture, kernel)
        plt.clf()
        plt.axis('off')
        plt.figimage(image)
        plt.gcf().set_size_inches((size / float(dpi), size / float(dpi)))
        plt.savefig('efield-%04d.png' % frame, dpi=dpi)
        frame += 1
else:
    kernellen = 31
    kernel = np.sin(np.arange(kernellen) * np.pi / kernellen)
    kernel = kernel.astype(np.float32)
    print(u.dtype, v.dtype, texture.dtype, kernel.dtype)
    print(u.shape, v.shape, texture.shape, kernel.shape)
    image = vp.line_integral_convolution(u, v, texture, kernel)
    plt.clf()
    plt.axis('off')
    plt.figimage(image)
    plt.gcf().set_size_inches((size / float(dpi), size / float(dpi)))
    plt.savefig('efield-image.png', dpi=dpi)

<mask token>
dpi = 100
size = 700
video = False
charges = [(10, +0.5, +0.5), (-10, -0.5, -0.5), (4, +0.2, -0.2)]
xs = np.linspace(-1, 1, size).astype(np.float32)[None, :]
ys = np.linspace(-1, 1, size).astype(np.float32)[:, None]
u = np.zeros((size, size), dtype=np.float32)
v = np.zeros((size, size), dtype=np.float32)
for q, x, y in charges:
    rsq = ((xs - x) ** 2 + (ys - y) ** 2) ** 1.5
    v += -q * (ys - y) / rsq
    u += -q * (xs - x) / rsq
texture = np.random.rand(size, size).astype(np.float32)
plt.bone()
frame = 0
if video:
    kernellen = 62
    steps = 125
    turns = 3
    for t in np.linspace(0, turns, steps, endpoint=False):
        kernel = vp.kernels.hanning_ripples(N=kernellen, shift=t)
        kernel = kernel.astype(np.float32)
        image = vp.line_integral_convolution(u, v, texture, kernel)
        plt.clf()
        plt.axis('off')
        plt.figimage(image)
        plt.gcf().set_size_inches((size / float(dpi), size / float(dpi)))
        plt.savefig('efield-%04d.png' % frame, dpi=dpi)
        frame += 1
else:
    kernellen = 31
    kernel = np.sin(np.arange(kernellen) * np.pi / kernellen)
    kernel = kernel.astype(np.float32)
    print(u.dtype, v.dtype, texture.dtype, kernel.dtype)
    print(u.shape, v.shape, texture.shape, kernel.shape)
    image = vp.line_integral_convolution(u, v, texture, kernel)
    plt.clf()
    plt.axis('off')
    plt.figimage(image)
    plt.gcf().set_size_inches((size / float(dpi), size / float(dpi)))
    plt.savefig('efield-image.png', dpi=dpi)

<mask token>
import numpy as np
import pylab as plt
import vectorplot as vp
dpi = 100
size = 700
video = False
charges = [(10, +0.5, +0.5), (-10, -0.5, -0.5), (4, +0.2, -0.2)]
xs = np.linspace(-1, 1, size).astype(np.float32)[None, :]
ys = np.linspace(-1, 1, size).astype(np.float32)[:, None]
u = np.zeros((size, size), dtype=np.float32)
v = np.zeros((size, size), dtype=np.float32)
for q, x, y in charges:
    rsq = ((xs - x) ** 2 + (ys - y) ** 2) ** 1.5
    v += -q * (ys - y) / rsq
    u += -q * (xs - x) / rsq
texture = np.random.rand(size, size).astype(np.float32)
plt.bone()
frame = 0
if video:
    kernellen = 62
    steps = 125
    turns = 3
    for t in np.linspace(0, turns, steps, endpoint=False):
        kernel = vp.kernels.hanning_ripples(N=kernellen, shift=t)
        kernel = kernel.astype(np.float32)
        image = vp.line_integral_convolution(u, v, texture, kernel)
        plt.clf()
        plt.axis('off')
        plt.figimage(image)
        plt.gcf().set_size_inches((size / float(dpi), size / float(dpi)))
        plt.savefig('efield-%04d.png' % frame, dpi=dpi)
        frame += 1
else:
    kernellen = 31
    kernel = np.sin(np.arange(kernellen) * np.pi / kernellen)
    kernel = kernel.astype(np.float32)
    print(u.dtype, v.dtype, texture.dtype, kernel.dtype)
    print(u.shape, v.shape, texture.shape, kernel.shape)
    image = vp.line_integral_convolution(u, v, texture, kernel)
    plt.clf()
    plt.axis('off')
    plt.figimage(image)
    plt.gcf().set_size_inches((size / float(dpi), size / float(dpi)))
    plt.savefig('efield-image.png', dpi=dpi)

"""Plot the electric field generated by three point charges in a plane."""

import numpy as np
import pylab as plt

import vectorplot as vp

dpi = 100
size = 700
video = False

# Charges : (q, x, y)
charges = [(10, +0.5, +0.5), (-10, -0.5, -0.5), (4, +0.2, -0.2)]

xs = np.linspace(-1, 1, size).astype(np.float32)[None, :]
ys = np.linspace(-1, 1, size).astype(np.float32)[:, None]

u = np.zeros((size, size), dtype=np.float32)
v = np.zeros((size, size), dtype=np.float32)

for (q, x, y) in charges:
    rsq = ((xs-x)**2+(ys-y)**2)**1.5
    v += -q * (ys-y)/rsq
    u += -q * (xs-x)/rsq

texture = np.random.rand(size, size).astype(np.float32)

plt.bone()
frame = 0

if video:
    kernellen = 62
    steps = 125
    turns = 3
    for t in np.linspace(0, turns, steps, endpoint=False):
        kernel = vp.kernels.hanning_ripples(N=kernellen, shift=t)

        kernel = kernel.astype(np.float32)

        image = vp.line_integral_convolution(u, v, texture, kernel)

        plt.clf()
        plt.axis('off')
        plt.figimage(image)
        plt.gcf().set_size_inches((size/float(dpi), size/float(dpi)))
        plt.savefig("efield-%04d.png" % frame, dpi=dpi)
        frame += 1
else:
    kernellen = 31
    kernel = np.sin(np.arange(kernellen)*np.pi/kernellen)
    kernel = kernel.astype(np.float32)
    print(u.dtype, v.dtype, texture.dtype, kernel.dtype)
    print(u.shape, v.shape, texture.shape, kernel.shape)

    image = vp.line_integral_convolution(u, v, texture, kernel)

    plt.clf()
    plt.axis('off')
    plt.figimage(image)
    plt.gcf().set_size_inches((size/float(dpi), size/float(dpi)))
    plt.savefig("efield-image.png", dpi=dpi)
