[ Launch Inlet ]
Gist #4434390 [ Launch Inlet ]
Gist #4434389
Gist #4429648 [ Launch Inlet ]
Gist #4429641 [ Launch Inlet ]
Gist #4429616 [ Launch Inlet ]
Gist #4429579 [ Launch Inlet ]
Gist #4425588 [ Launch Inlet ]
Gist #3200444
-
-
Save dwskau/4434753 to your computer and use it in GitHub Desktop.
Pythagorean Triples - comet
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
{"description":"Pythagorean Triples - comet","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"tab":"edit","display_percent":0.630672268907563,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"period","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"hidepanel":false} |
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
//draws all pythagorean triples with perimeters less than specified | |
d3.select('body').style('background', '#121212') | |
//max perimeter (CAUTION: high values take a long time to calculate) | |
var perimeter = 291; | |
//storage for the triples | |
var triples = []; | |
//calculate the triples (brute force) | |
for(var c=1; c<perimeter; c++) | |
for(var b=1; b<(perimeter-c); b++) | |
for(var a=1; a<(perimeter-(b+c)); a++) | |
if((a*a + b*b) === c*c) | |
triples.push({A:a, B:b, C:c}); | |
//draw the triples | |
var svg = d3.select("svg"); | |
var triangles = svg.append("svg:g"); | |
//var colorScale = d3.scale.category20(); | |
//var colorScale = d3.scale.ordinal() | |
// .range(["#0A8B58", "#1B8397", "#B63B3B"]) | |
var colorScale = d3.scale.linear() | |
.domain([0, perimeter]) | |
.range(["#FFFFFF", "#B4C1C7"]) | |
.interpolate(d3.interpolateHcl) | |
//.interpolate(d3.interpolateHsl) | |
triangles.selectAll().data(triples).enter().append('line') | |
.attr({ | |
"x1":function(d){return d.A}, | |
"y2":function(d){return d.B}, | |
"transform": "scale(" + 4.72 + ")" | |
}) | |
.style({ | |
"stroke": function(d,i) { | |
return colorScale(d.A+d.B+d.C); | |
}, | |
"stroke-width": perimeter, | |
"stroke-opacity": 0.03368 | |
}) | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment