[ Launch: mandelbrot ] 7095549 by jshumakerpruitt
-
-
Save jshumakerpruitt/7095549 to your computer and use it in GitHub Desktop.
mandelbrot_v2
This file contains hidden or 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":"mandelbrot_v2","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}},"fullscreen":false,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"pingpong","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"inline-console":true,"thumbnail":"http://i.imgur.com/4qlheg0.gif","ajax-caching":true} |
This file contains hidden or 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
var svg = d3.select("svg"); | |
var data = [] | |
var makeData = function(n){ | |
var temp = [] | |
var x = -2.5; | |
var y = -1; | |
for(var i = 0; i < Math.round(n*7/4); i++){ | |
for(var j = 0; j < n; j++){ | |
data.push({x: x + 3.5*i/(n*7/4), y: y + 2*j/n}); | |
} | |
} | |
}; | |
//makeData(70); | |
makeData(70); | |
//console.log(data); | |
var colors = d3.scale.linear().range(["#005CFF", "#FF0014"]) | |
//var colors = d3.scale.category20(); | |
var pickColor = function(x0,y0){ | |
var x = 0; | |
var y = 0; | |
var count = 0; | |
var max_iter = 1000; | |
while((x*x + y*y < 4) && count < max_iter){ | |
xtemp = x*x - y*y + x0; | |
y = 2*x*y+y0; | |
x = xtemp; | |
count++; | |
} | |
return colors(count/1000); | |
} | |
svg.selectAll("circle") | |
.data(data) | |
.enter() | |
.append("circle") | |
.attr({ | |
cx: function(d) {return 140*d.x + 423}, | |
cy: function(d) {return 140*d.y + 300}, | |
r: 1.9008, | |
fill: function(d,i){return pickColor(d.x, d.y)} | |
}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment