Skip to content

Instantly share code, notes, and snippets.

@aaizemberg
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaizemberg/d9f509d05ab6ac9c18c1 to your computer and use it in GitHub Desktop.
Save aaizemberg/d9f509d05ab6ac9c18c1 to your computer and use it in GitHub Desktop.
graphical perception (areas)
<!DOCTYPE HTML>
<html>
<head>
<script src="http://d3js.org/d3.v3.min.js"></script>
</head>
<body>
<canvas id="myCanvas" width="600" height="300" style="border:1px solid #bbb;"></canvas>
<script>
var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
var centerX = canvas.width / 2;
var centerY = canvas.height / 2;
var r = d3.scale.sqrt().domain([0, 100]).range([0, 100]);
var px = d3.scale.linear().domain([0, 1]).range([0, canvas.width]);
ctx.fillStyle = "#aaa";
//ctx.strokeStyle = "#aaa";
ctx.beginPath();
ctx.arc(px(1/4), centerY, r(50), 0, 2 * Math.PI);
ctx.fill();
//ctx.stroke();
ctx.beginPath();
ctx.arc(px(3/4), centerY, r(100), 0, 2 * Math.PI);
ctx.fill();
//ctx.stroke();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment