[ Launch: snake ] 5515892 by jvns
-
-
Save jvns/5515892 to your computer and use it in GitHub Desktop.
snake
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":"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} |
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
// 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