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
@anim = animate 5 do | |
keypress do |key| | |
case key | |
when :up, :down, :left, :right | |
snake.change_direction key | |
end | |
end | |
snake.move |
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
class GameItem | |
attr_accessor :x, :y | |
def initialize(app, x, y, colour = '#fff', fill = '#000000') | |
@app = app | |
@x = x | |
@y = y | |
@app.stroke colour | |
@app.fill fill | |
@rect = app.rect x * cell_size, y * cell_size, cell_size - 1, cell_size - 1 |
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
def add_brick_border | |
# Add bricks but don't record them for collision detection | |
# This draws the bricks for the horizontal bars | |
@boundary_y.each do |y| | |
@boundary_x.last.times do |x| | |
Brick.new(@app, x + 1, y) | |
end | |
end | |
# This draws the bricks for the vertical bars |
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
keypress do |key| | |
case key | |
when :up, :down, :left, :right | |
@snake.change_direction key | |
when 'r' | |
if @snake.dead | |
clear | |
setup_game self | |
@anim.start | |
end |
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
class Sounds | |
def initialize(app) | |
@app = app | |
@sounds = {} | |
end | |
def add_sound(sound_name, file_name) | |
@sounds[sound_name] = @app.video("sounds/#{file_name}", :top => 0, :left => 0) | |
end |
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
# Vlad the Deployer example suitable for Solaris | |
# Note: You'll need to configure the commands that restart your http/mongrel/etc processes | |
set :user, 'example' | |
set :application, 'example' | |
set :domain, 'example.com' | |
set :deploy_to, '/u/apps/example.com/' | |
set :repository, 'svn://example.com/path/to/svn/example/branch/production' |
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
# Fire | |
class Fire < Processing::App | |
def setup | |
color_mode RGB, 255 | |
background 0 | |
frame_rate 30 | |
end | |
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
def make_palette | |
palette = [] | |
# Create the bands of colour for the palette (256 is the maximum colour) | |
limit = 64 | |
multiplier = 256 / limit | |
(0..limit).each do |i| | |
# Range of reds | |
palette[i] = [i * multiplier, 0, 0] | |
# Orange | |
palette[i + limit] = [255, i * multiplier, 0] |
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
# Get the average pixel value | |
average = (left.to_i + right.to_i + (below.to_i * 2)) / 4 | |
# Fade the flames | |
average -= @intensity if average > @intensity | |
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
def test_relative_parsing_in_time_zones | |
Time.zone = 'Alaska' | |
# TODO: I've used Bob instead of Jan here because Jan switches it into January | |
# 1. Ensure time zones are working correctly | |
deadline = Deadline.create :description => 'Tell Bob to ring Vicki Friday 8pm', :user_id => users(:one).id | |
assert_equal deadline.due.hour, 20 | |
assert_equal deadline.due.strftime('%A'), 'Friday' | |
# 2. Now ensure relative times work |