Created
April 11, 2019 00:29
-
-
Save Nazek42/0009297cb49f46bd30cc952d011a52c9 to your computer and use it in GitHub Desktop.
CHAOS CONTROL
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 numpy as np | |
from scipy.ndimage.filters import generic_filter | |
from random import random | |
import matplotlib.pyplot as pp | |
import matplotlib | |
grid = np.random.rand(128, 128) | |
weights = [ 1, 2, 1, | |
2, 3, 2, | |
1, 2, 1, ] | |
p_initial = 1 | |
p_final = 0.3 | |
chaos_control = 0.95 | |
def update(arr): | |
new = np.average(arr, weights=weights) | |
if np.random.rand() < new: | |
new += np.random.rand()/10 * multiplier | |
else: | |
new -= np.random.rand()/10 * multiplier | |
return new | |
def maprange(x, a, b, c, d): | |
return (x - a) / (b - a) * (d - c) + c | |
pp.set_cmap(matplotlib.cm.get_cmap('terrain')) | |
p_chaos = p_initial | |
while True: | |
chaos = np.random.rand() < p_chaos | |
multiplier = [1, -1][chaos] | |
generic_filter(grid, update, size=(3,3), output=grid, mode='wrap') | |
np.clip(grid, 0, 1, out=grid) | |
pp.matshow(grid, fignum=0) | |
pp.title(str(p_chaos)) | |
pp.pause(0.001) | |
pp.cla() | |
if p_chaos > p_final: | |
p_chaos *= chaos_control | |
if p_chaos < p_final: | |
p_chaos = p_final | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment