Created
October 22, 2012 19:47
-
-
Save aedoran/3933634 to your computer and use it in GitHub Desktop.
Diff square tree
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
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<body> | |
<style> | |
path { | |
stroke-width:1px; | |
fill:red; | |
stroke:red; | |
} | |
</style> | |
<script src="http://d3js.org/d3.v2.min.js?2.9.7"></script> | |
<script> | |
var width = 2000, | |
height = 2000; | |
var svg = d3.select("body").append("svg:svg") | |
.attr("width", width) | |
.attr("height", height); | |
var line = d3.svg.line() | |
.x(function(d) { console.log(d); return d.x } ) | |
.y(function(d) { return d.y } ) | |
.interpolate("basis"); | |
var items = [], | |
w = 1000, | |
h = 1000, | |
pixel_space = .6; | |
pixel_scale = 1; | |
for (var i=1; i<=w; i++) { | |
for (var j=1; j<=h; j++) { | |
var sq = Math.pow(j,2), | |
en = sq - Math.pow(j-i,2); | |
if (Math.round(Math.sqrt(en)) == Math.sqrt(en)) { | |
items.push([ | |
{x:i*pixel_scale,y:j*pixel_scale}, | |
{x:(i*pixel_scale),y:(j*pixel_scale)+pixel_space}, | |
{x:(i*pixel_scale)+pixel_space,y:(j*pixel_scale)+pixel_space}, | |
{x:(i*pixel_scale)+pixel_space,y:(j*pixel_scale)}]); | |
} | |
} | |
} | |
svg.selectAll("path") | |
.data(items) | |
.enter().append("svg:path") | |
.attr("d",line) | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is teh brilliantsauce.