int hit=0; int miss=0; void setup() { size(500,600); background(255); noFill(); ellipse(width/2, width/2, width, width); fill(255); strokeWeight(2); textAlign(LEFT,CENTER); textSize(48); } void draw() { float x = random(width); float y = random(width); // stay within a square if (dist(x,y,width/2,width/2) <= width/2) { hit++; stroke(0, 255, 0); } else { miss++; stroke(255, 0, 0); } point(x,y); noStroke(); fill(204); rect(0, 1+width, width, height-width); float estimate = 4.0 * hit / (hit+miss); fill(0); text(nf(estimate, 1, 8), width/4, width + 0.5*(height-width)); }