#!/usr/bin/env python from __future__ import division import numpy as np from scipy import interpolate import matplotlib.pyplot as plt def noise(nnodes, amplitude): x = np.linspace(0, 1, nnodes) y = x z = amplitude * np.random.uniform(-1, +1, (nnodes, nnodes)) return interpolate.RectBivariateSpline(x, y, z) class Noise(object): def __init__(self, size, details=1): self._f = [noise(2**(size+n), 1/2**n) for n in range(details)] def __call__(self, x, y): return sum([f(x, y, grid=True) for f in self._f]) f = Noise(3, 6) x = np.linspace(0, 1, 1024) y = x with plt.style.context('ggplot'): plt.imshow(f(x, y)) plt.savefig('src03.png')