This commit is contained in:
Jay
2026-03-10 21:01:46 +00:00
commit 9006b2e06a
242 changed files with 30823 additions and 0 deletions

78
projects/piApprox.php Normal file
View File

@@ -0,0 +1,78 @@
<?php
if($_SERVER['HTTP_X_FORWARDED_PROTO'] !== 'https') {
header('Location: https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
die();
}
?>
<DOCTYPE! html>
<html>
<script src="https://cdn.jsdelivr.net/npm/p5@1.4.0/lib/p5.min.js"></script>
<h1 id="PIbox"></h1>
<h2 id="percentage"></h2>
<script>
const r = 400;
var circleCount, total;
var x, y;
var calcPI;
var DisplayPI = "a";
const PI = 3.1415926535;
var BestPI = 5;
function setup(){
createCanvas(r*2,r*2);
background(0);
stroke(255,0,0);
strokeWeight(1);
noFill()
translate(width/2, height/2);
rectMode(CENTER);
rect(0,0,r*2,r*2);
ellipse(0,0,r*2,r*2);
circleCount = 0;
total = 0;
}
function draw(){
translate(width/2, height/2);
for (var i = 0; i < 100; i++){
x = random(-r, r)
y = random(-r, r)
stroke(0,255,0)
total += 1
var d = dist(x,y,0,0)
if (d < r){
circleCount += 1
stroke(0,0,255)
}
point(x,y);
calcPI = 4 * (circleCount/total);
if (abs(PI-calcPI) < abs(PI-BestPI)){
DisplayPI = calcPI;
BestPI = calcPI;
var PIDisplay = document.getElementById("PIbox");
PIDisplay.innerHTML = DisplayPI;
var ErrorDisplay = document.getElementById("percentage");
var DisplayError = "a";
var Perror = (calcPI - 3.14159265359)/3.14159265359
Perror *= 100;
DisplayError = nfc(Perror, 10);
ErrorDisplay.innerHTML = DisplayError + '%';
}
}
}
</script>
</html>