This file contains hidden or 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
// Create a new hexagon with a radius of 100px at Point 200, 200 | |
var hexagon = new Path.RegularPolygon(new Point(200, 200), 6, 100); |
This file contains hidden or 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
<!DOCTYPE html> | |
<html lang='en'> | |
<head> | |
<title>Hexagon</title> | |
</head> | |
<body> | |
<!-- Create a canvas and give it the attribute "resize" this tells Paper.js the canvas should be the size of the entire browser window --> | |
<canvas id='background-hexagons' resize></canvas> |
This file contains hidden or 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
// Create a Paper.js Path to draw a line into it: | |
var hexagon = new Path(); | |
// Color our path black | |
hexagon.strokeColor = 'black'; | |
// How many points do we want our object to have | |
var points = 6; | |
// How large should it be | |
var radius = 60; | |
// 0 to 2PI is a circle, so divide that by the number of points |
This file contains hidden or 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
var TodoView = Backbone.View.extend({ | |
tagName: 'li', | |
template: _.template($('#item-template').html()), | |
// Ensure our view knows about the association to it's model | |
initialize: function() { | |
this.model.bind('change', this.render, this); | |
}, | |
// Drop that model into the template and have the template re-render |
This file contains hidden or 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
<script type="text/x-handlebars"> | |
The President of the United States is {{MyApp.president.fullName}}. | |
</script> |
This file contains hidden or 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
window.Game = Backbone.Model.extend({ | |
// Must define this for API endpoint | |
urlRoot: '/games', | |
// Set defaults like so | |
defaults: { | |
'players': 2 | |
} | |
}); |
This file contains hidden or 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
// Create model extending from Spine Model | |
window.Game = Spine.Model.sub({ | |
// No documentation about this, refered to in controller documenation | |
init: function() { | |
this.players = 2; | |
} | |
}); | |
// What accessors does it have? | |
Game.configure('Game', 'players'); |
This file contains hidden or 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
class Board < ActiveRecord::Base | |
belongs_to :game | |
# After initialize we generate new tiles and store them in the objects tiles accessor | |
# When this model is retrieved through ActiveRecord the tiles are not generated and we get the | |
# tile set that was saved in the database. | |
after_initialize :place_tiles | |
def place_tiles | |
# The tiles hash is stored in a text field, Rails handles this |
This file contains hidden or 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
def generate_tiles | |
# Pass the number of tiles into the main hash | |
tiles = { | |
ore: 3, # Ore | |
brick: 3, # Brick | |
wheat: 4, # Wheat | |
lumber: 4, # Trees | |
wool: 4, # Wool, Robber | |
robber: 1}.map { |k, v| | |
# After creating tile count, lets map them |
This file contains hidden or 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
box = {x: 10, y: 10, width: 40, height: 50, vX: 5, vY: 5}; | |
bounds = {left: 0, right: 800, top: 0, bottom: 400}; | |
frame() { | |
box.nX = box.x + box.vX; | |
box.nY = box.y + box.vY; | |
if(box.nX < bounds.left) box.vX *= -1; | |
if(box.nX + box.width > bounds.right) box.vX *= -1; |