Skip to content

Instantly share code, notes, and snippets.

View Breefield's full-sized avatar

Bree Hoffman Breefield

View GitHub Profile
// Create a new hexagon with a radius of 100px at Point 200, 200
var hexagon = new Path.RegularPolygon(new Point(200, 200), 6, 100);
@Breefield
Breefield / hexagon-canvas.html
Created August 12, 2012 04:23
Hexagon Canvas
<!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>
@Breefield
Breefield / hexagon.js
Created August 12, 2012 04:12
Drawing a Hexagon with Paper.js
// 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
@Breefield
Breefield / backbone-bind.js
Created August 10, 2012 20:43
Backbone.js Template Binding
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
@Breefield
Breefield / ember-binding.html
Created August 10, 2012 20:36
Ember.js Mustache Binding Example
<script type="text/x-handlebars">
The President of the United States is {{MyApp.president.fullName}}.
</script>
@Breefield
Breefield / backbone-game.js
Created August 9, 2012 20:42
Game Model in Backbone.js
window.Game = Backbone.Model.extend({
// Must define this for API endpoint
urlRoot: '/games',
// Set defaults like so
defaults: {
'players': 2
}
});
@Breefield
Breefield / spine-game.js
Created August 9, 2012 20:37
Game Model in Spine.js
// 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');
@Breefield
Breefield / board.rb
Created August 9, 2012 01:54
Generate Board on Initialize
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
@Breefield
Breefield / tile.rb
Created August 9, 2012 01:47
Make a Tile Layout
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
@Breefield
Breefield / gist:1454316
Created December 10, 2011 02:20
Bounce
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;