Module: Soby
- Included in:
- Presentation, PresentationLoader
- Defined in:
- lib/soby/launcher.rb,
lib/soby/transforms.rb
Constant Summary collapse
- SLEEP_TIME =
5
Class Method Summary collapse
- .auto_update(soby_player) ⇒ Object
- .find_files ⇒ Object
- .find_files_except(name) ⇒ Object
-
.load_presentation(svg_name) ⇒ Object
def Soby.load_presentation (program_name, svg_name) puts “Loading program” load program_name puts “Loading prez” (PresentationLoader.new($app, $app.sketchPath(svg_name), program_name)).presentation end.
-
.reload_presentation(presentation) ⇒ Object
local use.
- .start_presentation(presentation) ⇒ Object
Instance Method Summary collapse
- #create_mat4x4(mat) ⇒ Object
- #get_angle(mat) ⇒ Object
- #get_global_transform(element) ⇒ Object
- #read_transform(text) ⇒ Object
Class Method Details
.auto_update(soby_player) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/soby/launcher.rb', line 19 def Soby.auto_update soby_player puts "Sketch Root" + SKETCH_ROOT files = find_files svg_name = soby_player.prez.url time = Time.now soby_player.thread = Thread.new { loop do if files.find { |file| FileTest.exist?(file) && File.stat(file).mtime > time } puts 'reloading sketch...' time = Time.now presentation = (PresentationLoader.new($app, svg_name)).presentation start_presentation presentation end sleep SLEEP_TIME return if $app == nil end } end |
.find_files ⇒ Object
59 60 61 |
# File 'lib/soby/launcher.rb', line 59 def Soby.find_files Dir.glob(File.join(SKETCH_ROOT, "**/*.{svg,glsl,rb}")) end |
.find_files_except(name) ⇒ Object
55 56 57 |
# File 'lib/soby/launcher.rb', line 55 def Soby.find_files_except (name) find_files.select { |file_name| not file_name.end_with? name } end |
.load_presentation(svg_name) ⇒ Object
def Soby.load_presentation (program_name, svg_name)
puts "Loading program"
load program_name
puts "Loading prez"
(PresentationLoader.new($app, $app.sketchPath(svg_name), program_name)).presentation
end
14 15 16 |
# File 'lib/soby/launcher.rb', line 14 def Soby.load_presentation(svg_name) PresentationLoader.new($app, $app.sketchPath(svg_name)).presentation end |
.reload_presentation(presentation) ⇒ Object
local use
45 46 47 48 49 |
# File 'lib/soby/launcher.rb', line 45 def Soby.reload_presentation (presentation) # load presentation.program # presentation.reset presentation = Soby::load_presentation(presentation.program, presentation.url) end |
.start_presentation(presentation) ⇒ Object
51 52 53 |
# File 'lib/soby/launcher.rb', line 51 def Soby.start_presentation (presentation) $app.set_prez presentation end |
Instance Method Details
#create_mat4x4(mat) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/soby/transforms.rb', line 45 def create_mat4x4(mat) Matrix4x4.new(mat.m00, mat.m01, mat.m02, mat.m03,\ mat.m10, mat.m11, mat.m12, mat.m13,\ mat.m20, mat.m21, mat.m22, mat.m23,\ mat.m30, mat.m31, mat.m32, mat.m33) end |
#get_angle(mat) ⇒ Object
40 41 42 |
# File 'lib/soby/transforms.rb', line 40 def get_angle (mat) Math.atan2(mat.m01, mat.m00) end |
#get_global_transform(element) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/soby/transforms.rb', line 20 def get_global_transform element e = element global_transform = PMatrix3D.new attr = e.attributes global_transform.translate(attr["x"].value.to_f, attr["y"].value.to_f) while e.class != Nokogiri::XML::Document do t = e.attribute("transform") if (t != nil) tr = read_transform(t.value) global_transform.preApply(tr) end e = e.parent end [global_transform , attr["width"].value.to_f, attr["height"].value.to_f] end |
#read_transform(text) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/soby/transforms.rb', line 6 def read_transform (text) if(text.match("matrix")) text = text.split(/[,\(]/) # split with , or ( return PMatrix2D.new(text[1].to_f, text[3].to_f, text[5].to_f, \ text[2].to_f, text[4].to_f, text[6].to_f) if(text.size == 7) end if(text.match("translate")) text = text.split(/[,\(]/) return PMatrix2D.new(1, 0, text[1].to_f, 0, 1, text[2].to_f) end end |