/* built with Studio Sketchpad:
* https://sketchpad.cc
*
* observe the evolution of this sketch:
* https://studio.sketchpad.cc/sp/pad/view/ro.hue1aqcTkbJ/rev.2927
*
* authors:
*
* jayroscope
*
*
* :p
*
*
*
*
*
*
* botconboy
* botconboy
* Panda Bear
* orange pikachu
*
*
* Richard Ames
*
*
* lovemeforever
* Owen
* overlord809
* license (unless otherwise specified):
* creative commons attribution-share alike 3.0 license.
* https://creativecommons.org/licenses/by-sa/3.0/
*/
// This sketch builds on a prior work, "Pong", created by Richard Ames
// http://studio.sketchpad.cc/sp/pad/view/ro.9yKwmwLQwPe9l/rev.56
// Pressing Control-R will render this sketch.
// Intent is to calculate pi using Monte Carlo method
int xp;
int yp;
int s = 300; /* square size */
int r; /* circle radius */
int n; /* inside circle */
int m; /* total of all random guesses */
int pitch = 10;
/* bitmap for 3 x 5 dot matrix font for numerals */
var numzero[] = [1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1];
var numone[] = [0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1];
var numtwo[] = [1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1];
var numthree[] = [1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1];
var numfour[] = [1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1];
var numfive[] = [1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1];
var numsix[] = [1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1];
var numseven[] = [1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1];
var numeight[] = [1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1];
var numnine[] = [1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1];
var digits[] = [numzero, numone, numtwo, numthree, numfour,
numfive, numsix, numseven, numeight, numnine];
int drawnumeral(int sx, int sy, int value)
{
int i = 0;
if ((value >= 0) && (value <= 9))
{
stroke(#ff00ff);
for (i = 0; i < numzero.length; i++)
{
if (digits[value][i])
point(sx, sy);
sx += pitch;
if ((i + 1) % 3 == 0)
{
sy += pitch;
sx -= pitch * 3;
}
}
}
}
int drawvalue(int nval, int mval)
{
var i;
var ratio = 4 * mval / nval;
var ratiostr = ratio.toPrecision(5);
for (i = 0; i < ratiostr.length; i++)
{
drawnumeral(40 + 40 * i, 120, ratiostr.charCodeAt(i) - 0x30);
}
}
void setup() { // this is run once.
// set the background color
background(0 ,255 ,0);
// canvas size (Variables aren't evaluated. Integers only, please.)
size(s, s);
// smooth edges
smooth();
// limit the number of frames per second
frameRate(50);
// set the width of the line.
strokeWeight(10);
r = s / 2;
n = 0;
m = 0;
}
void draw() { // this is run repeatedly.
x = random(0, s);
y = random(0, s);
xp = x - s / 2;
yp = y - s / 2;
n++;
if (xp * xp + yp * yp < r * r)
{
stroke(#A3D1FF);
m++;
}
else
{
stroke(#111111);
}
point(x, y);
if (m % 200 == 0)
drawvalue(n, m);
}