Method: VIBes.begin_drawing
- Defined in:
- lib/vibes-rb.rb
.begin_drawing(fname = nil) ⇒ self
Open communication with the VIBes viewer. If the viewer is not executing, forks to launch it in a new process.
Normaly the user do not have to call this function, it is automatically called when the first message is being sent to the viewer.
It is only useful when the user wants to save the commands in a specific file instead of sending them to the viewer. In this case, this method should be called before any figure method is called.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/vibes-rb.rb', line 54 def self.begin_drawing(fname = nil) if fname.kind_of?(String) and not(fname.empty?) then @@vibes_channel.close if @@vibes_channel @@vibes_channel = File.open(fname, 'a') else user_dir = ENV['USERPROFILE'] # windows user_dir = ENV['HOME'] if user_dir.nil? if user_dir then # Environment variable found, connect to a file in user's profile directory fname = File.join(user_dir, '.vibes.json') unless File.exist?(fname) then Process.detach(fork{Process.exec('VIBes-viewer')}) startTime = Time.now until File.exist?(fname) do sleep 0.1 if (Time.now - startTime) > 1 then warn 'VIBes-viewer process does not seem to be started' break end end end begin_drawing(fname) else # Connect to a file in working directory begin_drawing('vibes.json') end end self end |