package math.integration;

import stdlib.Color;
import stdlib.StdDraw;

/**
 * 
 * @author Daniel
 *
 */
public class Dartboard {

    public static void main(String[] args) {
        int N = Integer.parseInt(args.length!=0?args[0]:"1000"); // N-by-N lattice

    	StdDraw sd = new StdDraw();
    	
        // dartboard background
        StdDraw.clear(Color.LIGHT_GRAY);

        // large bullseye
        sd.setPenColor(Color.GRAY);
        StdDraw.filledCircle(.5, .5, .5);

        StdDraw.show();

        // throw random points at the dartboard
        sd.setPenColor(Color.BLACK);
        int yes = 0;
        for (int i = 0; i < N; i++) {
            double x = Math.random();
            double y = Math.random();
            if (x*x + y*y <= 1.0) yes++;
            sd.point(x, y);
        }

        // results
        double fraction = 1.0 * yes / N;
        System.out.println("Fraction that hit dartboard = " + fraction);
    }
}