SQ Script Functions

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.

firstrun

Determine whether the SQ script is run for the first time.

Syntax

b = firstrun

Description

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.

Example

if firstrun
  x = rand(1,10);
end
if _id == 1
  x(_ix) = _y1;
end
plot(1:10, x, '', 1);

_id

ID of the manipulated graphic object.

Syntax

n = _id

Description

When a graphic 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 [].

Example

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);

_ix

Index of the manipulated graphic element.

Syntax

n = _ix

Description

When a graphic 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 [].

Example

if firstrun
  y = rand(1,10);
end
if ~isempty(_ix)
  y(_ix) = _y1;
end
plot(y, 'g', 1);

_kx _ky

Ratio between current and previous position during a manipulation.

Syntax

kx = _kx
ky = _ky

Description

When the button of the mouse is held down over a graphic object drawn with an ID argument larger than zero, _kx gives the ratio between the horizontal position of the mouse and the current horizontal position of the object; in all other cases, _x0 is the empty array []. _kx is typically used to change a scale or a gain. _ky does the same vertically.

Example

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);

See also

_x0, _y0, _z0, _x1, _y1, _z1

_nb

Number of the manipulated trace.

Syntax

n = _nb

Description

When a graphic 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 [].

Example

if firstrun
  Y = rand(5,10);
end
if ~isempty(_nb)
  Y(_nb,_ix) = _y1;
end
plot(Y, 'b', 1);

_m

State of the Shift key during a manipulation.

Syntax

b = _m

Description

During a manipulation with the mouse, _m is true if the Shift key is held down or false otherwise.

_q

Plot-specific value.

Syntax

q = _q

Description

When a graphic object drawn with an ID argument larger than zero is manipulated with the mouse, _q gives a value which depends on the graphic; in all other cases, _ix is the empty array []. Not all graphics define a value for _q.

Example

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);

_x _y _z

Mouse position when the button was pressed.

Syntax

x = _x
y = _y
z = _z

Description

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.

Example

% 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

See also

_x0, _y0, _z0, _x1, _y1, _z1

_x0 _y0 _z0

Current position of the object being manipulated with the mouse.

Syntax

x = _x0
y = _y0
z = _z0

Description

When the button of the mouse is held down over a graphic 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.

See also

_x, _y, _z, _x1, _y1, _z1

_x1 _y1 _z1

Current position of the mouse during a manipulation.

Syntax

x = _x1
y = _y1
z = _z1

Description

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.

See also

_x0, _y0, _z0, _x, _y, _z


Copyright 2001, Calerga.

All rights reserved.