Sha256: 32a165e9470c899912b8f4decaa756f82e729d4c66a9c56f8ae84b11ecbb9108

Contents?: true

Size: 1.29 KB

Versions: 7

Compression:

Stored size: 1.29 KB

Contents

# encoding: utf-8
# frozen_string_literal: false

SKETCH_PATH ||= ARGV.shift
SKETCH_ROOT ||= File.absolute_path(File.dirname(SKETCH_PATH))

# we can safely require app.rb as we are using a jruby runtime
require_relative '../app'

# More processing module
module Processing
  # For use with "bare" sketches that don't want to define a class or methods
  BARE_WRAP = <<-EOS
  class Sketch < Processing::App
    %s
  end
  EOS

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

    def settings
      size(150, 150)
    end
  end
  EOS

  # This method is the common entry point to run a sketch, bare or complete.
  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 $app
      return
    end
    code = no_methods ? format(NAKED_WRAP, source) : format(BARE_WRAP, source)
    Object.class_eval code, SKETCH_PATH, -1
    Processing::App.sketch_class.new unless $app
  end

  # Read in the sketch source code. Needs to work both online and offline.
  def self.read_sketch_source
    File.read(SKETCH_PATH)
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
jruby_art-1.2.5 lib/jruby_art/runners/base.rb
jruby_art-1.2.4 lib/jruby_art/runners/base.rb
jruby_art-1.2.3 lib/jruby_art/runners/base.rb
jruby_art-1.2.1 lib/jruby_art/runners/base.rb
jruby_art-1.2.0.pre lib/jruby_art/runners/base.rb
jruby_art-1.1.3 lib/jruby_art/runners/base.rb
jruby_art-1.1.2 lib/jruby_art/runners/base.rb