Module: Soby

Included in:
Presentation
Defined in:
lib/soby/launcher.rb,
lib/soby/transforms.rb

Constant Summary collapse

SLEEP_TIME =
1

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.auto_update(presentation, file_not_updated) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/soby/launcher.rb', line 15

def Soby.auto_update (presentation, file_not_updated)
  
  if $app != nil 
    
    files = find_files_except file_not_updated
    start_presentation presentation

    program_name = presentation.program
    svg_name = presentation.url
    
    time = Time.now 
    
    t = Thread.new {
      loop do

        if files.find { |file| FileTest.exist?(file) && File.stat(file).mtime > time }
          puts 'reloading sketch...'
          
          time = Time.now

          load program_name
          presentation = Presentation.new($app, $app.sketchPath(svg_name), program_name)
          start_presentation presentation
        end

        sleep SLEEP_TIME
        return if $app == nil
      end
    }
  end
end

.find_filesObject



64
65
66
# File 'lib/soby/launcher.rb', line 64

def Soby.find_files
  Dir.glob(File.join(SKETCH_ROOT, "**/*.{svg,glsl,rb}"))
end

.find_files_except(name) ⇒ Object



60
61
62
# File 'lib/soby/launcher.rb', line 60

def Soby.find_files_except (name)
  find_files.select { |file_name| not file_name.end_with? name }
end

.load_presentation(program_name, svg_name) ⇒ Object

used outside



8
9
10
11
12
13
# File 'lib/soby/launcher.rb', line 8

def Soby.load_presentation (program_name, svg_name)
  puts "Loading program"
  load program_name
  puts "Loading prez"
  Presentation.new($app, $app.sketchPath(svg_name), program_name)
end

.reload_presentation(presentation) ⇒ Object

local use



50
51
52
53
54
# File 'lib/soby/launcher.rb', line 50

def Soby.reload_presentation (presentation)
#    load presentation.program
#    presentation.reset
  presentation =  Soby::load_presentation(presentation.program, presentation.url)
end

.start_presentation(presentation) ⇒ Object



56
57
58
# File 'lib/soby/launcher.rb', line 56

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