Skip to content

Instantly share code, notes, and snippets.

@sxywu
Last active February 5, 2017 02:54
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 sxywu/11e312147e3de1615d7b01aaef153df0 to your computer and use it in GitHub Desktop.
Save sxywu/11e312147e3de1615d7b01aaef153df0 to your computer and use it in GitHub Desktop.
Harry Potter colors
license: mit
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.15.0/lodash.min.js"></script>
<script type="text/javascript" src="http://gka.github.io/chroma.js/vendor/chroma-js/chroma.min.js"></script>
<style>
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; }
</style>
</head>
<body>
<script>
var colors = chroma.scale(['#fff1ec', '#ed3282']);
var colors2 = chroma.scale(['#fff1ec', '#ad32ed'])
colors = [colors(0), colors(0.25), colors(0.5), colors(0.75), colors(1),
colors2(0), colors2(0.25), colors2(0.5), colors2(0.75), colors2(1)];
var svg = d3.select("body").append("svg")
.attr("width", 960)
.attr("height", 500)
var perRow = 5;
var size = 100;
var g = svg.selectAll('g')
.data(colors).enter().append('g')
.attr('transform', (d, i) => {
var x = (i % perRow + 1) * size;
var y = (Math.floor(i / perRow) + 1) * size;
return 'translate(' + [x, y] + ')';
}).attr('fill', d => d);
g.append('circle')
.attr('r', size / 4);
g.append('text')
.attr('y', size / 4 + 36)
.attr('text-anchor', 'middle')
.attr('dy', '.35em')
.text((d, i) => d);
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment