Skip to content

Instantly share code, notes, and snippets.

@godfat
Created June 15, 2012 18:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save godfat/2938180 to your computer and use it in GitHub Desktop.
Save godfat/2938180 to your computer and use it in GitHub Desktop.
RubyMotion
class AppDelegate
attr_accessor :window
def application(application, didFinishLaunchingWithOptions:launchOptions)
self.window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
window.rootViewController = Controller.alloc.init
window.rootViewController.wantsFullScreenLayout = true
window.makeKeyAndVisible
true
end
end
class Controller < UIViewController
def loadView
self.view = View.alloc.init.construct
NSTimer.scheduledTimerWithTimeInterval(1.0/30.0,
target:view, selector:'timerFired', userInfo:nil, repeats:true)
end
end
class View < UIView
attr_accessor :i, :step, :flip
def construct
self.i = 0
self.step = 1
self.flip = true
self
end
def timerFired
self.i += step
setNeedsDisplay
end
def drawRect rect
r, g, b, a = rainbows
UIColor.colorWithRed(r, green:g, blue:b, alpha:a).set
UIBezierPath.bezierPathWithRect(frame).fill
end
def touchesEnded touches, withEvent:event
puts "Clicked #{step}"
self.flip = !flip if step >= 50 || step <= 0
self.step = 1 if step == 0
if flip
self.step *= 2
else
self.step /= 2
end
end
private
def rainbows freq=0.01
r = Math.sin(freq*i + 0*Math::PI/3) + 0.5;
g = Math.sin(freq*i + 2*Math::PI/3) + 0.5;
b = Math.sin(freq*i + 4*Math::PI/3) + 0.5;
[r, g, b, 1.0]
end
end
require 'rubygems/specification'
require 'rubygems/dependency'
require 'net/http'
require 'openssl'
require 'zlib'
$bunmo_output = File.open("#{ARGV.first}.rb", 'a')
$bunmo_loaded = {}
class Object
alias_method :require_ruby, :require
end
def require name
return if $bunmo_loaded[name]
path = Gem.find_files("#{name}.rb").first
return warn("#{name} not found: #{caller[-3]}") unless path
$bunmo_loaded = path
require_ruby name
$bunmo_output.puts(File.read(path).
gsub(/require(\(| ).+$/, ''))
end
require ARGV.first
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment