Skip to content

Instantly share code, notes, and snippets.

@jvns
Created May 4, 2013 02:48
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 jvns/5515892 to your computer and use it in GitHub Desktop.
Save jvns/5515892 to your computer and use it in GitHub Desktop.
snake
{"description":"snake","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":"period","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01}
// snake = [[1,2], [1,3], [1,4], [2,4], [3,4], [3,5], [4,5]]
snake = [[1,1]]
food = [[1,2], [3,5], [4,9]]
svg = d3.select('svg')
gridsize = 23
scale = d3.scale.linear()
.domain([0, gridsize])
.range([0, 600])
svg.selectAll('rect.snake')
.data(snake)
.enter()
.append('rect')
.attr('class', 'snake')
.attr('width', scale(1))
.attr('height', scale(1))
.attr('x', function(d) {return scale(d[0])})
.attr('y', function(d) {return scale(d[1])});
svg.selectAll('rect.food')
.data(food)
.enter()
.append('rect')
.attr('class', 'food')
.attr('width', scale(1))
.attr('height', scale(1))
.attr('x', function(d) {return scale(d[0])})
.attr('y', function(d) {return scale(d[1])});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment