'''
Created on Jan 23, 2012

@author: ola
'''

import matplotlib.pyplot as plt
import numpy as np
import math
import random

def circle():
    xs = [0.01*x for x in range(101)] 
    ys = [math.sqrt(1-x*x) for x in xs]
    plt.plot(xs,ys)

def point(n):
    inside = 0;
    plt.axis('scaled')
    plt.axis([0,1.1,0,1.1])
    for dummy in range(n):
        x = random.random()
        y = random.random()
        
        if x*x + y*y <= 1.0:
            inside += 1
            plt.plot(x,y,'ro')
        else:
            plt.plot(x,y,'bo')
    return inside

if __name__ == "__main__":
    darts = 50000
    circle()
    inside = point(darts)
    plt.axhline(1.0,0.0,1.0,color='black')
    plt.axvline(1.0,0.0,1.0)
    plt.show()
    print "pi = %.8f\n" % (inside*4.0/darts)