Class: Propane::App

Inherits:
PApplet
  • Object
show all
Includes:
Math, MathTool, HelperMethods
Defined in:
lib/propane/app.rb

Overview

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

i.e.

class MySketch < Propane::App

def draw
  background rand(255)
end

end

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HelperMethods

#blend_color, #buffer, #color, #dist, #find_method, #frame_rate, #grid, #int_to_ruby_colors, #java_self, #kamera, #lerp_color, #load_strings, #max, #min, #perspektiv, #save_strings, #set_sketch_path, #sketch_path, #thread, #web_to_color_array

Constructor Details

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

Returns a new instance of App.

Raises:

  • (TypeError)


65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/propane/app.rb', line 65

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object (private)



157
158
159
# File 'lib/propane/app.rb', line 157

def method_missing(name, *args)
  self.class.__send__(name, *args) if PApplet.public_methods.include?(name)
end

Class Attribute Details

.library_loaderObject

Handy getters and setters on the class go here:



39
40
41
# File 'lib/propane/app.rb', line 39

def library_loader
  @library_loader
end

.sketch_classObject

Handy getters and setters on the class go here:



39
40
41
# File 'lib/propane/app.rb', line 39

def sketch_class
  @sketch_class
end

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



31
32
33
# File 'lib/propane/app.rb', line 31

def arguments
  @arguments
end

#optionsObject (readonly)

Returns the value of attribute options.



31
32
33
# File 'lib/propane/app.rb', line 31

def options
  @options
end

#titleObject (readonly)

Returns the value of attribute title.



31
32
33
# File 'lib/propane/app.rb', line 31

def title
  @title
end

Class Method Details

.library_loaded?(library_name) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/propane/app.rb', line 47

def library_loaded?(library_name)
  library_loader.library_loaded?(library_name)
end

.load_java_library(*args) ⇒ Object



55
56
57
# File 'lib/propane/app.rb', line 55

def load_java_library(*args)
  library_loader.load_java_library(*args)
end

.load_libraries(*args) ⇒ Object Also known as: load_library



41
42
43
44
# File 'lib/propane/app.rb', line 41

def load_libraries(*args)
  library_loader ||= LibraryLoader.new
  library_loader.load_library(*args)
end

.load_ruby_library(*args) ⇒ Object



51
52
53
# File 'lib/propane/app.rb', line 51

def load_ruby_library(*args)
  library_loader.load_ruby_library(*args)
end

Instance Method Details

#keyObject

Fix java conversion problems getting the last key If it’s ASCII, return the character, otherwise the integer



106
107
108
109
# File 'lib/propane/app.rb', line 106

def key
  int = @declared_fields['key'].value(java_self)
  int < 256 ? int.chr : int
end

#key_pressed?Boolean

Is a key pressed for this frame?

Returns:

  • (Boolean)


100
101
102
# File 'lib/propane/app.rb', line 100

def key_pressed?
  @declared_fields['keyPressed'].value(java_self)
end

#library_loaded?(library_name) ⇒ Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/propane/app.rb', line 60

def library_loaded?(library_name)
  self.class.library_loaded?(library_name)
end

#mouse_pressed?Boolean

Is the mouse pressed for this frame?

Returns:

  • (Boolean)


95
96
97
# File 'lib/propane/app.rb', line 95

def mouse_pressed?
  @declared_fields['mousePressed'].value(java_self)
end

#run_sketchObject

This method runs the processing sketch.



90
91
92
# File 'lib/propane/app.rb', line 90

def run_sketch
  PApplet.run_sketch(arguments, self)
end

#size(*args) ⇒ Object



79
80
81
82
83
84
85
86
# File 'lib/propane/app.rb', line 79

def size(*args)
  w, h, mode       = *args
  @width           ||= w
  @height          ||= h
  @render_mode     ||= mode
  import_opengl if /opengl/ =~ mode
  super(*args)
end