Class: Ribiprocessing::SimpleApp

Inherits:
PApplet
  • Object
show all
Defined in:
lib/ribiprocessing/simple_app.rb

Overview

This class is the base class the user should inherit from when making their own sketch.

i.e.

class MySketch < SimpleApp

def draw
  background rand(255)
end

end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}, arguments = []) ⇒ SimpleApp

SimpleApp should be instantiated with an optional list of options and array of arguments.

SimpleApp.new(width: 500, height: 500, headless: true)

Raises:

  • (TypeError)


29
30
31
32
33
34
35
36
37
38
39
# File 'lib/ribiprocessing/simple_app.rb', line 29

def initialize options={}, arguments=[]
  # Guard against invalid input.
  raise TypeError unless options.is_a?   Hash
  raise TypeError unless arguments.is_a? Array
  # Set up the sketch.
  super()
  @arguments = arguments
  @options   = options
  configure_sketch
  run_sketch
end

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



22
23
24
# File 'lib/ribiprocessing/simple_app.rb', line 22

def arguments
  @arguments
end

#optionsObject (readonly)

Returns the value of attribute options.



22
23
24
# File 'lib/ribiprocessing/simple_app.rb', line 22

def options
  @options
end

#titleObject (readonly)

Returns the value of attribute title.



22
23
24
# File 'lib/ribiprocessing/simple_app.rb', line 22

def title
  @title
end

Instance Method Details

#drawObject

This method is the main draw loop of the sketch. This must be overridden by the user.



53
54
55
# File 'lib/ribiprocessing/simple_app.rb', line 53

def draw
  raise "please define a draw method on the SimpleApp subclass."
end

#run_sketchObject

This method runs the processing sketch.



59
60
61
# File 'lib/ribiprocessing/simple_app.rb', line 59

def run_sketch
  PApplet.run_sketch(arguments, self)
end

#setupObject

This method provides the default setup for the sketch. It can be overridden by the user for finer grained control.



44
45
46
47
48
# File 'lib/ribiprocessing/simple_app.rb', line 44

def setup
  width  = options.fetch(:width,  800)
  height = options.fetch(:height, 640)
  size(width, height)
end