﻿from random import *
import numpy as np
import matplotlib.pyplot as plt

def carre_orange():
    x=[-1,-1,1,1,-1]
    y=[-1,1,1,-1,-1]
    plt.plot(x,y,c='orange')

def carre_bleu():
    x=[-1,0,1,0,-1]
    y=[0,1,0,-1,0]
    plt.plot(x,y,c='blue')

def interieur_carre(x,y):
    if x>=0 and y>=0 and y<=-x+1:
        return "oui"
    if x>=0 and y<0 and y>=x-1:
        return "oui"
    if x<0 and y<0 and y>=-x-1:
        return "oui"
    if x<0 and y>=0 and y<=x+1:
        return "oui"
    return "non"

def nuage_points(n):
    compteur=0
    for k in range(0,n):
        x=uniform(-1,1)
        y=uniform(-1,1)
        reponse=interieur_carre(x,y)
        if reponse=="oui":
            plt.scatter(x,y,c='blue')
            compteur=compteur+1
        else:
            plt.scatter(x,y,c='orange')
    return compteur

def aire(n):
    carre_orange()
    carre_bleu()
    c=nuage_points(n)
    fq=c/n
    plt.show()
    return fq

