mario-sanz / pi-approximation

Graphical Pi approximation in JavaScript (see Readme file)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Pi approximation

This code approximates the number Pi.

A circle is drawn representing the random dots that we generate. If a dot is inside our defined circle, it will be painted in green. If it is outside, it will be red.

The best approximation is also written in the console, that is, if we have a number whose difference (absolute value) to the real Pi number is smaller than the previous best approximation, we write it.

Below you can see some examples of how many dots the circle had and how much precise the approximation was. The more dots, the best approximation. The code can be tested by cloning/downloading this repository and running it on the p5.js web editor.

Stars in GitHub are appreciated!

If you have any further questions or suggestions, don't hesitate to ask me here: Questions and issues

Developer: mario-sanz

Graphical representation examples

3 14191419141917

Pi approximation value (MY CODE): 3.14191419141917

Pi value (REAL): 3.1415926535897932

3 1415990730011587

Pi approximation value (MY CODE): 3.1415990730011587

Pi value (REAL): 3.1415926535897932

3 141592666034428

Pi approximation value (MY CODE): 3.141592666034428

Pi value (REAL): 3.1415926535897932

3 1415926719499985

Pi approximation value (MY CODE): 3.1415926719499985

Pi value (REAL): 3.1415926535897932

About

Graphical Pi approximation in JavaScript (see Readme file)


Languages

Language:JavaScript 71.6%Language:HTML 23.8%Language:CSS 4.6%