Module: Processing

Defined in:
lib/jruby_art.rb,
lib/jruby_art/app.rb,
lib/jruby_art/runner.rb,
lib/jruby_art/launcher.rb,
lib/jruby_art/runners/base.rb,
lib/jruby_art/runners/watch.rb,
lib/jruby_art/helper_methods.rb,
lib/jruby_art/library_loader.rb

Overview

The processing wrapper module

Defined Under Namespace

Modules: HelperMethods, Proxy, Render Classes: App, Launcher, LibraryLoader, Runner, WatchException, Watcher

Constant Summary collapse

RP_CONFIG =
conf.config
BARE_WRAP =

For use with “bare” sketches that don’t want to define a class or methods

<<-EOS.freeze
class Sketch < Processing::App
  %s
end
EOS
NAKED_WRAP =
<<-EOS.freeze
class Sketch < Processing::App
  def setup
    sketch_title '%s'
    %s
    no_loop
  end

  def settings
    size(%d, %d)
  end
end
EOS

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.appObject

Returns the value of attribute app.



37
38
39
# File 'lib/jruby_art/app.rb', line 37

def app
  @app
end

.surfaceObject

Returns the value of attribute surface.



37
38
39
# File 'lib/jruby_art/app.rb', line 37

def surface
  @surface
end

Class Method Details

.load_and_run_sketchObject

This method is the common entry point to run a sketch, bare or complete.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/jruby_art/runners/base.rb', line 32

def self.load_and_run_sketch
  source = read_sketch_source
  wrapped = !source.match(/^[^#]*< Processing::App/).nil?
  no_methods = source.match(/^[^#]*(def\s+setup|def\s+draw)/).nil?
  if wrapped
    load SKETCH_PATH
    Processing::App.sketch_class.new unless Processing.app
    return
  end
  name = RP_CONFIG.fetch('sketch_title', 'Naked Sketch')
  width = RP_CONFIG.fetch('width', 200)
  height = RP_CONFIG.fetch('height', 200)
  code = no_methods ? format(NAKED_WRAP, name, source, width, height) : format(BARE_WRAP, source)
  Object.class_eval code, SKETCH_PATH, -1
  Processing::App.sketch_class.new unless Processing.app
end

.read_sketch_sourceObject

Read in the sketch source code. Needs to work both online and offline.



50
51
52
# File 'lib/jruby_art/runners/base.rb', line 50

def self.read_sketch_source
  File.read(SKETCH_PATH)
end