Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/jandot/ruby-processing
Browse files Browse the repository at this point in the history
Former-commit-id: 0fb08ab
Former-commit-id: 067869a32064bf80780217c078e831011531e14e
  • Loading branch information
jashkenas committed Jul 13, 2009
2 parents 873e791 + 7043c81 commit 7c8174d
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 4 deletions.
11 changes: 9 additions & 2 deletions lib/ruby-processing/app.rb
Expand Up @@ -156,9 +156,8 @@ def self.load_java_library(dir)
def self.has_slider(*args) #:nodoc:
raise "has_slider has been replaced with a nicer control_panel library. Check it out."
end


# When you make a new sketch, you pass in (optionally),
# When you make a new sketch, you pass in (optionally),
# a width, height, title, and whether or not you want to
# run in full-screen.
#
Expand All @@ -176,6 +175,14 @@ def initialize(options={})
@title = options[:title] || default_title
@render_mode ||= JAVA2D
@@full_screen ||= options[:full_screen]

# To make arbitrary options available as attributes
options.keys.each do |key|
next if [:width, :height, :title, :full_screen].include?(key)
self.class.send :attr_accessor, key
send "#{key}=".to_sym, options[key]
end

self.init
determine_how_to_display
end
Expand Down
9 changes: 7 additions & 2 deletions lib/ruby-processing/exporters/base_exporter.rb
Expand Up @@ -90,7 +90,7 @@ def extract_real_requires(source)
requirements = []
partial_paths = []
loop do
matchdata = code.match(/^.*\b(require|load)\b.*$/)
matchdata = code.match(/^.*[^::|\.](require|load)\b.*$/)
break unless matchdata
line = matchdata[0].gsub('__FILE__', "'#{@main_file_path}'")
line = line.gsub(/\b(require|load)\b/, 'partial_paths << ')
Expand All @@ -105,7 +105,12 @@ def extract_real_requires(source)
protected

def read_source_code
File.read(@main_file_path)
lines = File.readlines(@main_file_path)
lines.each do |line|
prev_version = line
line.sub!(/#[^\{].*/, '')
end
return lines.join("\n")
end

def local_dir
Expand Down
36 changes: 36 additions & 0 deletions samples/extended_initialization.rb
@@ -0,0 +1,36 @@
require File.dirname(__FILE__) + '/../lib/ruby-processing.rb'

class MySketch < Processing::App
attr_accessor :extended_option

# Let's define a setup method, for code that gets
# run one time when the app is started.
def setup
background 0
no_stroke
smooth
frame_rate 10

@font = create_font('Helvetica', 16)
text_font @font
@rotation = 0
end

# And the draw method which will be called repeatedly.
# Delete this if you don't need animation.
def draw
fill 0
rect 0, 0, width, height

translate width/2, height/2
rotate @rotation

fill 255
text @message, 20, 20
# ellipse 0, -60, 20, 20

@rotation += 0.1
end
end

S = MySketch.new :title => 'extended_initialization', :width => 500, :height => 500, :message => 'Any text goes here...'

0 comments on commit 7c8174d

Please sign in to comment.