SQ scripts are simple programs for Sysquake. Instead of relying on declarations to instruct Sysquake what code to execute to display graphics or react to user interaction, they contain only LME statements and expressions. Sysquake execute them from beginning to end when the script is loaded and when the user resize the window or click its contents. A small set of functions has been added to support interactivity; they are described below. They cannot be used from the command-line interface or in SQ files.
Determine whether the SQ script is run for the first time.
b = firstrun
firstrun returns true if the SQ script is run for the first time after loading or reset, or false otherwise. For SQ scripts with interactive graphics, it should be used to give an initial value to variables which can later be manipulated by the user.
if firstrun x = rand(1,10); end if _id == 1 x(_ix) = _y1; end plot(1:10, x, '', 1);
Displacement between current and previous position during a manipulation.
dx = _dx dy = _dy
When the button of the mouse is held down, _dx gives the horizontal displacement from the previous to the current position of the mouse; it is equivalent to _x1-_x. _dy give the vertical displacement.
ID of the manipulated graphics object.
n = _id
When a graphics object drawn with an ID argument larger than zero is manipulated with the mouse, _id gives its ID; in all other cases, _id is the empty array [].
if firstrun y = 3; x = 2; end switch _id case 1 % the horizontal line is being manipulated y = _y1; case 2 % the vertical line is being manipulated x = _x1; end line([0,1], y, 'b', 1); line([1,0], x, 'r', 2);
Index of the manipulated graphical element.
n = _ix
When a graphical object drawn with an ID argument larger than zero is manipulated with the mouse, _ix gives the index of the point being manipulated; in all other cases, _ix is the empty array [].
if firstrun y = rand(1,10); end if ~isempty(_ix) y(_ix) = _y1; end plot(y, 'g', 1);
Ratio between current and previous position during a manipulation.
kx = _kx ky = _ky
When the button of the mouse is held down, _kx gives the ratio between the horizontal position of the mouse and the previous horizontal position; it is equivalent to _x1/_x. _kx is typically used to change a scale or a gain. _ky does the same vertically.
if firstrun num = 1; den = [1,2,3,4]; end if ~isempty(_ky) % change the gain of the transfer function num/den num = _ky * num; end step(num,den,'b',1);
Number of the manipulated trace.
n = _nb
When a graphical object drawn with an ID argument larger than zero is manipulated with the mouse, _nb gives the number of the trace being manipulated; in all other cases, _ix is the empty array [].
if firstrun Y = rand(5,10); end if ~isempty(_nb) Y(_nb,_ix) = _y1; end plot(Y, 'b', 1);
State of the Shift key during a manipulation.
b = _m
During a manipulation with the mouse, _m is true if the Shift key is held down or false otherwise.
Plot-specific value.
q = _q
When a graphical object drawn with an ID argument larger than zero is manipulated with the mouse, _q gives a value which depends on the graphics; in all other cases, _ix is the empty array []. Not all graphics define a value for _q.
Root locus where the closed-loop and open-loop poles may be manipulated:
if firstrun
% define an initial transfer function
num = -1;
den = 1:4;
end
switch _id
case 1
% gain change
num = num * _q;
case 2
% new location of open-loop poles
den = movezero(den, _z0, _z1);
end
scale('equal',[-3,1,-2,2]);
sgrid;
% root locus for a gain >= 0
rlocus(num,den,'r',1);
% closed-loop poles on the root locus
plotroots(addpol(num,den),'^',1);
% open-loop poles (gain=0)
plotroots(den, 'x', 2);
Mouse position when the button was pressed.
x = _x y = _y z = _z
When the button of the mouse is held down, _x gives the horizontal position at the instant when the button was pressed; in all other cases, _x is the empty array []. _y gives the vertical position; _z gives the horizontal and vertical position as a complex number.
% define a region where the user can click scale([0,10,0,10]); if ~isempty(_x) % draws a line between the mousedown position % and the current position plot([_x,_x1],[_y,_y1]); end
Current position of the object being manipulated with the mouse.
x = _x0 y = _y0 z = _z0 p = _p0
When the button of the mouse is held down over a graphical object drawn with an ID argument larger than zero, _x0 gives its current horizontal position; in all other cases, _x0 is the empty array []. _y0 gives the vertical position; _z0 gives the horizontal and vertical position as a complex number; and _p0 gives the position as a 2D vector for 2D graphics and as a 3D vector for 3D graphics.
_x, _y, _z, _x1, _y1, _z1, _p1
Current position of the mouse during a manipulation.
x = _x1 y = _y1 z = _z1 p = _p1
When the button of the mouse is held down, _x1 gives the current horizontal position of the mouse; otherwise (when the button is up), _x1 is the empty array []. _y1 gives the vertical position; _z1 gives the horizontal and vertical position as a complex number; and _p1 gives the position as a 2D vector for 2D graphics and as a 3D vector for 3D graphics, using the associated surface set by sensor3.