Created
November 7, 2017 02:17
-
-
Save yvan/eafa24f258ec519e84eb837bdad6cde5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
center_x, center_y = shape[1] // 2, shape[0] // 2 | |
circle_grad = np.zeros_like(world) | |
for y in range(world.shape[0]): | |
for x in range(world.shape[1]): | |
distx = abs(x - center_x) | |
disty = abs(y - center_y) | |
dist = math.sqrt(distx*distx + disty*disty) | |
circle_grad[y][x] = dist | |
# get it between -1 and 1 | |
max_grad = np.max(circle_grad) | |
circle_grad = circle_grad / max_grad | |
circle_grad -= 0.5 | |
circle_grad *= 2.0 | |
circle_grad = -circle_grad | |
# shrink gradient | |
for y in range(world.shape[0]): | |
for x in range(world.shape[1]): | |
if circle_grad[y][x] > 0: | |
circle_grad[y][x] *= 20 | |
# get it between 0 and 1 | |
max_grad = np.max(circle_grad) | |
circle_grad = circle_grad / max_grad | |
toimage(circle_grad).show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment