#!/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 = amplitude * np.random.uniform(-1, +1, nnodes) return interpolate.interp1d(x, y, kind='cubic') 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): return sum([f(x) for f in self._f]) f = Noise(3, 5) x = np.linspace(0, 1, 1000) with plt.style.context('ggplot'): plt.plot(x, f(x)) plt.savefig('src02.png')