Contents Previous Next Subchapters

Slowing or Suspending Execution
Syntax sleep
sleep(option)
See Also pause , clock , time

Description
Slows or suspends O-Matrix execution. If option is an integer, real or double-precision scalar, it specifies the number of seconds to wait before continuing execution. If option is the string "off" (or "OFF"), subsequent calls to sleep are ignored. If option is the string "on" (or "ON"), subsequent calls to sleep are not ignored. If option is not present, execution is suspended until the user selects a continue button in a special dialog that is displayed.

Example
     for i = 1 to 5 begin
          print i
          sleep(1)
     end
Will print the numbers 1 though 5 at a rate of one number per second.

You can use the sleep function when creating animated graphics. The following example animates a sine wave though one cycle.
     theta  = 0. : .1 : 2 * pi
     for i = 0 to 50 begin
          alpha = 2 * pi * i / 50.
          ginitview
          gplot(theta, sin(alpha + theta))
          gxaxis("offlin", 0., 2 * pi);
          gyaxis("offlin", -1., 1.)
          gupdate
          sleep(.2)
     end

Mlmode
In Mlmode this function is called pause instead of sleep. If in Mlmode you enter
     for i = 1:5 
          i
          pause(1)
     end
O-Matrix will print the numbers 1 though 5 at a rate of one number per second.

Reference
The clear command resets the sleep function to the "on" state.