Skip to content

Instantly share code, notes, and snippets.

@domitry

domitry/README.md

Created Nov 9, 2015
Embed
What would you like to do?

Scatter: Nyaplotjs v2

<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