Skip to content

Instantly share code, notes, and snippets.

@georules
Last active August 29, 2015 14:13
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 georules/4cfa40801525d56f757f to your computer and use it in GitHub Desktop.
Save georules/4cfa40801525d56f757f to your computer and use it in GitHub Desktop.
test
{"description":"test","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}},"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,"tab":"edit","display_percent":0.7,"thumbnail":"http://i.imgur.com/hRUYJyB.png","fullscreen":false,"ajax-caching":true,"inline-console":false}
var svg = d3.select("svg")
d3.select("body").style("background-color",d3.rgb(25,25,25))
var colors = [
'#fe2d85'
, '#4DA9DF'
, '#37ff00'
, '#fed075'
]
tall = 15
times = 14
var color = function(i) {
var num_interps = colors.length -1
var ord = d3.scale.linear()
.domain([0, times])
.range([0, num_interps])
var section = parseInt(ord(i))
//console.log("section", section)
var section_size = times / num_interps
//get the two colors we want to interpolate between
var col_range = [colors[section], colors[section+1]]
var col_scale = d3.scale.linear()
.domain([section * section_size, (section+1) * section_size])
//.interpolate(d3.interpolateRgb)
.interpolate(d3.interpolateHsl)
.range(col_range)
return col_scale(i)
}
num = 14
fibs = new Array()
for (i = num; i >= 0; i--) {
d = fib(i)
fibs[i] = d
for(j = 0; j < times; j++) {
drawthing(d/4, tall,i*2+d+10, j*tall*2,j)
drawthing(d/4, tall,(num-i)-d*1.275+788, tall+j*tall*2,j)
}
}
function fib(n) {
if (n < 2) {
return 1;
} else {
return fib(n - 2) + fib(n - 1);
}
}
function drawthing(w,h,x,y,i) {
c = color(i)
svg.append("rect")
.attr({
width: w,
height: h,
x: x+20,
y: y,
fill: c
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment