Page MenuHome

File Metadata

Author
Daniel M. Basso (dmbasso)
Created
Nov 13 2013, 5:09 PM
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import numpy as np
from numpy import linalg
s = 80
def force_field(grid, p, c1, c2, exp):
dist = np.apply_along_axis(linalg.norm, 2, grid - p)
strenght = c1 / (1 + (c2 * dist) ** exp)
return (p - grid) * strenght[:,:,np.newaxis].repeat(2, axis=2)
def save_grid(fname, grid):
with open(fname, "w") as out:
out.write("{} {} {}".format(
grid.shape[0], grid.shape[1],
' '.join(str(f) for f in grid.flat)
))
def distorted_grid(angle):
grid = np.zeros((s, s, 2))
grid[:,:,0] = np.linspace(.3, .7, s).reshape((1, s)).repeat(s, axis=0)
grid[:,:,1] = np.linspace(.4, .6, s).reshape((s, 1)).repeat(s, axis=1)
p = np.array([
.48+ .02 * np.cos(np.pi * angle / 180),
.5 + .02 * np.sin(np.pi * angle / 180),
])
p2 = np.array([
.65 + .03 * np.cos(np.pi * -angle * 2 / 180 + .1),
.46 + .03 * np.sin(np.pi * -angle * 2 / 180 + .1),
])
p3 = np.array([
.35 + .03 * np.cos(np.pi * -angle * 4 / 180 + .1),
.46 + .03 * np.sin(np.pi * -angle * 4 / 180 + .1),
])
grid += (
force_field(grid, p, .9, 23.5, 4)
+ force_field(grid, p2, .9, 23.5, 3)
- force_field(grid, p3, .7, 33.5, 2)
)
return grid
#for i in range(0, 360, 5):
# grid = distorted_grid(i)
# save_grid("map.txt", grid)
# from matplotlib import pyplot as plt
# plt.clf()
# plt.scatter(grid[:,:,0], grid[:,:,1])
# plt.xlim([0.2, .8])
# plt.ylim([.3, .7])
# plt.ginput()
for i in range(1, 151):
print i
angle = i / 150. * 360
grid = distorted_grid(angle)
save_grid("/tmp/map{}.txt".format(i), grid)

Event Timeline