Advertisement
Binary_Crusader

π approximation (processing)

Nov 8th, 2018
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. double pointsQuantity=0;
  2. double pointsInEllipse=0;
  3. double result=0;
  4.  
  5. void setup ()
  6. {
  7. size (100, 100);
  8. background (255);
  9. stroke (0);
  10. noFill();
  11. smooth();
  12. }
  13.  
  14. void draw()
  15. {
  16. rect(0, 0, 100, 100);
  17. translate(50,50);
  18. ellipse(0,0,100,100);
  19.  
  20. float x = random(-50,50);
  21. float y = random(-50,50);
  22.  
  23. point(x,y);
  24. pointsQuantity = pointsQuantity +1;
  25.  
  26. if (x*x+y*y <= 50*50)
  27. {
  28. pointsInEllipse = pointsInEllipse+1;
  29. }
  30.  
  31. result = pointsInEllipse/pointsQuantity;
  32. result = result*4;
  33.  
  34. print (result + " ");
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement