Created
November 9, 2015 11:45
-
-
Save domitry/4e9e02acc18ad6b83d56 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Scatter with Nyaplotjs</title> | |
<script src='http://d3js.org/d3.v3.min.js'></script> | |
<script src='https://cdn.rawgit.com/domitry/Nyaplotjs/a1b10b68f08cfbd5afc4e145103ac46297951d45/release/nyaplot.min.js'></script> | |
<script> | |
window.onload = function(){ | |
var inside={x: [], y: []}, outside={x: [], y: []}, N=7000; | |
for(var i=0;i < N;i++){ | |
var x= Math.random(); | |
var y= Math.random(); | |
if(Math.sqrt(x*x+y*y)<1.0){ | |
inside.x.push(x); | |
inside.y.push(y); | |
}else{ | |
outside.x.push(x); | |
outside.y.push(y); | |
} | |
} | |
var plot = new Nyaplot.Plot(); | |
var sc1 = new Nyaplot.Scatter(inside.x, inside.y, {color: "#1b9e77"}); | |
var sc2 = new Nyaplot.Scatter(outside.x, outside.y, {color: "#d95f02"}); | |
plot.add([sc1, sc2]); | |
plot.show("vis"); | |
d3.select("#N").text(N); | |
d3.select("#PI").text(4*inside.x.length/N); | |
}; | |
</script> | |
</head> | |
<body> | |
<h1>PI = ?</h1> | |
N=<span id="N"></span>, PI~=<span id="PI"></span> | |
<br> | |
<div id="vis"></div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment