const Pixi = require('pixi.js')

const TILE_SIZE = 8

class Tile {
  constructor (x, y) {
    this.x = x
    this.y = y
    this.food = getRandomInt(0, 255)
    this.rectangle = new Pixi.Graphics()
  }

  render () {
    this.rectangle.beginFill(foodToRgb(this.food))
    this.rectangle.drawRect(this.x * TILE_SIZE, this.y * TILE_SIZE, TILE_SIZE, TILE_SIZE)
    this.rectangle.endFill()
  }
}

// http://stackoverflow.com/a/1527820/6360623
function getRandomInt (min, max) {
  return Math.floor(Math.random() * (max - min + 1)) + min
}

function foodToRgb (food) {
  // food is 8-bit number. Copy it 3 times by moving to the left and inserting another copy.
  return (((food << 8) | food) << 8) | food
}

module.exports = Tile

@@ -567,94 +567,64 @@
  // 
-food is 8-bit number. Copy it 3 times by moving to the left and inserting another copy
+2-digit hex number (0-255 dec) three times: 56 -%3E 565656
 .%0A  
@@ -634,37 +634,43 @@
 urn 
-((
 (food 
-%3C%3C 8) %7C food) %3C%3C 8) %7C
+* 0x10000) + (food * 0x100) +
  foo

use a more obvious and clear algorithm in `foodToRgb`