Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

here it goes..

  • Loading branch information...
commit b5d3972b568733c8c780ff4a05b47651b4b7e300 0 parents
@despo authored
2  .gitignore
@@ -0,0 +1,2 @@
+.sass-cache/
+.rvmrc
10 Gemfile
@@ -0,0 +1,10 @@
+source :rubygems
+
+gem 'sinatra'
+gem 'haml'
+
+group :development do
+ gem 'sinatra-reloader'
+ gem 'guard-coffeescript'
+ gem 'coffee-script'
+end
50 Gemfile.lock
@@ -0,0 +1,50 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ backports (2.4.0)
+ coffee-script (2.2.0)
+ coffee-script-source
+ execjs
+ coffee-script-source (1.2.0)
+ eventmachine (0.12.10)
+ execjs (1.3.0)
+ multi_json (~> 1.0)
+ ffi (1.0.11)
+ guard (1.0.1)
+ ffi (>= 0.5.0)
+ thor (~> 0.14.6)
+ guard-coffeescript (0.5.6)
+ coffee-script (>= 2.2.0)
+ guard (>= 0.8.3)
+ haml (3.1.4)
+ multi_json (1.1.0)
+ rack (1.4.1)
+ rack-protection (1.2.0)
+ rack
+ rack-test (0.6.1)
+ rack (>= 1.0)
+ sinatra (1.3.2)
+ rack (~> 1.3, >= 1.3.6)
+ rack-protection (~> 1.2)
+ tilt (~> 1.3, >= 1.3.3)
+ sinatra-contrib (1.3.1)
+ backports (>= 2.0)
+ eventmachine
+ rack-protection
+ rack-test
+ sinatra (~> 1.3.0)
+ tilt (~> 1.3)
+ sinatra-reloader (1.0)
+ sinatra-contrib
+ thor (0.14.6)
+ tilt (1.3.3)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ coffee-script
+ guard-coffeescript
+ haml
+ sinatra
+ sinatra-reloader
3  config.ru
@@ -0,0 +1,3 @@
+require './lib/gorillas'
+
+run Gorillas::App
24 lib/gorillas.rb
@@ -0,0 +1,24 @@
+require 'sinatra/base'
+require 'haml'
+require 'coffee-script'
+
+module Gorillas
+ class App < Sinatra::Base
+
+ set :haml, :format => :html5
+ set :views, "#{Dir.pwd}/views"
+
+ get '/' do
+ haml :index
+ end
+
+ get "/gorillas.js" do
+ content_type "text/javascript"
+ coffee :gorillas
+ end
+
+ get "/style.css" do
+ scss :style
+ end
+ end
+end
39 views/gorillas.coffee
@@ -0,0 +1,39 @@
+class Building
+ constructor:(context, color) ->
+ @context = context
+ @width = 200
+ @height = 400
+ @color = color
+
+ draw:(x,y) ->
+ @context.fillStyle = @color
+ @height = @height - y
+ @context.fillRect x, 600-@height, @width, @height
+ @build_windows(x, y)
+
+ build_windows:(x, y) ->
+ height = 600 - @height
+ @context.fillStyle = '#FFFF00'
+ @context.fillRect x+z, height+y, 15, 30 for z in [ 35, 70, 105, 140, 175]
+
+class Painter
+ constructor: ->
+ @canvas = document.getElementById "gorillas"
+ @context = @canvas.getContext "2d"
+ @color = '#00FFFF'
+
+ draw_building:(x, y) ->
+ building = new Building(@context, @color)
+ building.draw(x, y)
+
+ set_color:(color) ->
+ @color = color
+
+window.onload = ->
+ painter = new Painter
+ painter.draw_building(40, 20)
+ painter.draw_building(245, 5)
+
+ painter.set_color '#800000'
+ painter.draw_building(450, 25)
+ painter.draw_building(655, 15)
2  views/index.haml
@@ -0,0 +1,2 @@
+%h1 Coffeescipt Gorillas
+%canvas{ :id => "gorillas", :width => "1024", :height => "640" }
8 views/layout.haml
@@ -0,0 +1,8 @@
+!!!
+%html
+ %head
+ %link{:rel => "stylesheet", :href => "/style.css", :type => "text/css", :media => "all"}
+ %script{:type => "text/javascript", :src => "/gorillas.js"}
+ %title Gorillas in canvas
+ %body
+ = yield
3  views/style.scss
@@ -0,0 +1,3 @@
+body {
+ background-color: #0000FF
+}
Please sign in to comment.
Something went wrong with that request. Please try again.