#!/usr/bin/env python

import sys
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as anim

N = 1000
which = 1
if len(sys.argv) > 1: which = 2

def get_points(n):
    x = np.random.uniform(-1, 1, N)
    y = np.random.uniform(-1, 1, N)
    return x,y
    
def add_points(i):		# add N new points
    x,y = get_points(N)
    points, = plt.plot(x, y, 'b.', markersize=0.5)
    plt.title(str(i))
    return points,
    
def move_points(i):		# move existing points
    x,y = get_points(N)
    points.set_data(x, y)
    plt.title(str(i))
    return points,
    
fig = plt.figure()
ax = fig.add_subplot(111)
ax.set_xlim(-1.1, 1.1)
ax.set_ylim(-1.1, 1.1)
points, = add_points(0)		# first set of points

if which == 1:
    ani = anim.FuncAnimation(fig, move_points, blit=False, interval=200)
else:
    ani = anim.FuncAnimation(fig, add_points, blit=False, interval=200)

plt.show()
