Appendix A2: Standard predicates for geometric objects

View(Out V)

Declare windows by enumeration
Description:

The visualization system repeatedly calls this predicate to build one or more views. A view is a rectangular area used to contain graphical objects and has its own local coordinates system. Actually a view is a window. Each view must have a unique ID.

Predicate type:

Enumerative

Parameters:

V ID of the view to be declared
Attributes: ViewOrigin, ViewColor
Example:
/** View(Out 1); **/

"Declare a window with label 1"

If no graphical object is declared to be inside view 1, the result will be an empty window on the screen.

ViewOrigin(Out X,Out Y,V)

Declare the (X,Y) origin of the view V

Description:

The visualization system calls this predicate to gather the coordinates system origin of the view V. Coordinates of graphical objects inside V will be relative to the (X,Y) origin specified by ViewOrigin. We recall that X grows from left to right and Y from top to bottom and are relative to the left-top corner of the view.

If ViewOrigin is not declared or is false for a given view V, the default origin is assumed to be (0,0) that is the left-top corner.

Predicate type:

Single value

Parameters:

X

X coordinate of the origin (in pixels from view's left edge)

Y

Y coordinate of the origin (in pixels from view's top edge )

V

ID of the view

Example:

/** ViewOrigin(Out 10,Out 20,V) If V==1 || V==2; **/

"Declare that the origin of view 1 and view 2 is (10,20)"

ViewColor(Out C,V)

Declare the background color C of the view V

Description:

The visualization system calls this predicate to gather the background color of the view V.

If ViewColor is not declared or is false for a given view V, the default background color is White.

Predicate type:

Single value

Parameters:

C

background color of the view V

V

ID of the view

Example:

/** ViewColor(Out Grey,_); **/

"Declare that the background color of every view is Grey"

Point(Out P,Out X,Out Y,V)

Declare points in the view V by enumeration

Description:

The visualization system repeatedly calls this predicate for each view V to gather information (ID and position) about points to be drawn inside it.

Each point must be assigned an ID number that will be used declare its attributes. Note if two points are given the same ID their attributes (color, size, shape) won't be different in any way.

Predicate type:

Enumerative

Parameters:

P

ID of the point(s) (two points may have the same ID)

X

X coordinate of the point (in pixels) from the origin of view V

Y

Y coordinate of the point (in pixels) from the origin of view V

V

ID of the view that will contain the point(s)

Attributes:

PointColor, PointSize, PointShape

Example:

struct { 
    int x,y; 
} q[5]={ {10,10}, {20,20}, {30,30}, {40,40}, {50,50} }; 

/** 
    View(Out 1); 
    Point(Out P,Out X,Out Y,1) 
        For P:InRange(P,0,4) 
        Assign X=q[P].x Y=q[P].y; 
**/

"Declare a view whose label is 1. Then declare 5 points inside view 1 whose coordinates are held in the external array q".

Note each point has a different ID enumerated by the InRange built-in predicate.

This example yields the following result:

PointSize(P,Out S,V)

Declare the size S of points having ID equal to P in the view V

Description:

The visualization system calls this predicate to gather the size of all points having ID equal to P in the view V.

Default:

If PointSize is not declared or is false for a given point, the default size is 1 pixel.

Predicate type:

Single value

Parameters:

P

ID of the point(s) we are explicitly giving a size

S

size (in pixels) of the point(s) with ID equal to P in the view V

V

ID of the view that contains the point(s)

Example:

/** PointSize(P,Out S,1) Assign S=(P+1)*2; **/

"Declare the size of every point having ID equal to P in the view 1 to be (P+1)*2"

The following result is obtained by adding the code above to the example given for Point:

PointColor(P,Out C,V)

Declare the color C of points having ID equal to P in the view V

Description:

The visualization system calls this predicate to gather the color of all points having ID equal to P in the view V.

Default:

If PointColor is not declared or is false for a given point, the default color is Grey.

Predicate type:

Single value

Parameters:

P

ID of the point we are explicitly giving a color

C

color of the point with ID equal to P in the view V

V

ID of the view that contains the point(s)

Example:

/** PointColor(P,Out C,1) Assign C=P; **/

"Declare the color of every point having ID equal to P in the view 1 to be the P-th color of the standard color table"

The following result is obtained by adding the code above to the examples given for Point and PointSize:

PointShape(P,Out S,V)

Declare the shape S of points having ID equal to P in the view V

Description:

The visualization system calls this predicate to gather the shape of all points having ID equal to P in the view V.

Default

If PointShape is not declared or is false for a given point, the default shape is Square.

Predicate type:

Single value

Parameters:

P

ID of the point we are explicitly giving a shape

S

shape (Round or Square) of point(s) with ID equal to P in the view V

V

ID of the view that contains the point(s)

Example:

/** PointShape(P,Out Round,1) If P%2==1; **/

"Declare the shape of every point having ID equal to P in the view 1 to be Round if P is odd"

The following result is obtained by adding the code above to the examples given for Point, PointSize, and PointColor:

Line(Out L,Out X1,Out Y1,Out X2,Out Y2,V)

Declare lines in the view V by enumeration

Description:

The visualization system repeatedly calls this predicate for each view V to gather information (ID and position) about lines to be drawn inside it.

Each line must be assigned an ID number that will be used declare its attributes. Note if two lines are given the same ID their attributes (color, thickness, style) won't be different in any way.

Predicate type:

Enumerative

Parameters:

L

ID of the line(s) (two lines may have the same ID)

X1

X coordinate of line's start point (in pixels from the origin of view V)

Y1

Y coordinate of line's start point (in pixels from the origin of view V)

X2

X coordinate of line's end point (in pixels from the origin of view V)

Y2

Y coordinate of line's end point (in pixels from the origin of view V)

V

ID of the view that will contain the line(s)

Attributes:

LineColor, LineThickness, LineStyle

Example:

/** 
View(Out 1);
ViewOrigin(Out 20,Out 10,1);
Line(Out 1,Out 0,Out Y1,Out X2,Out 100,1)
For L:InRange(L,0,10)
Assign Y1,X2=L*10;
**/

"Declare a view whose label is 1 and declare its origin as (20,10). Then declare 11 distinct lines inside view 1"

Note all lines have the same ID=1.

This example yields the following result:

LineColor(L,Out C,V)

Declare the color C of lines having ID equal to L in the view V

Description:

The visualization system calls this predicate to gather the color of all lines having ID equal to L in the view V

Default:

If LineColor is not declared or is false for a given line, the default color is Grey.

Predicate type:

Single value

Parameters:

L

ID of the line(s) we are explicitly giving a color

C

color of the line(s) with ID equal to L in the view V

V

ID of the view that contains the line(s)

Example:

/** 
ViewColor(Out Black,1);
LineColor(1,Out Yellow,1);
**/

"Declare the background color of view 1 to be Black. Then declare the color of every line having ID equal to 1 in the view 1 to be Yellow"

The following result is obtained by adding the code above to the example given for Line:

LineThickness(L,Out T,V)

Declare the thickness T of lines having ID equal to L in the view V

Description:

The visualization system calls this predicate to gather the thickness of all lines having ID equal to L in the view V.

Default:

If LineThickness is not declared or is false for a given line, the default thickness is Thin (1 pixel).

Predicate type:

Single value

Parameters:

L

ID of the line(s) we are explicitly giving a color

T

thickness (in pixels) of the line(s) with ID equal to L in the view V

V

ID of the view that contains the line(s)

Example:

/** 
View(Out 1);
Line(Out L,Out X1,Out 10,Out X2,Out 70,1)
For L:InRange(L,1,6)
Assign X1,X2=L*20;
LineThickness(L,Out T,1) Assign T=L;
**/

"Declare view 1. Then declare 6 vertical lines with ID from 1 to 6 and declare their thickness to be equal to their ID"

This example yields the following result:

LineStyle(L,Out S,V)

Declare the style S of lines having ID equal to L in the view V

Description:

The visualization system calls this predicate to gather the style of all lines having ID equal to L in the view V. The style of a line may be either Solid or Dashed.

Default:

If LineStyle is not declared or is false for a given, the default style is Solid.

Predicate type:

Single value

Parameters:

L

ID of the line(s) we are explicitly giving a style

S

style (Solid or Dashed) of the line(s) with ID equal to L in the view V

V

ID of the view that contains the line(s)

Example:

/** LineStyle(L,Out S,1) Assign S=(L%2==0) ? Solid:Dashed; **/

"All lines with even ID in the view 1 are Solid; lines with odd ID are Dashed"

The following result is obtained by adding the code above to the example given for LineThickness:

Rectangle(Out R,Out X,Out Y,Out L,Out H,V)

Declare rectangles in the view V by enumeration

Description:

The visualization system repeatedly calls this predicate for each view V to gather information (ID position and size) about rectangles to be drawn inside it.

Each rectangle must be assigned an ID number that will be used to declare its attributes. Note if two rectangles are given the same ID their attributes (color, framecolor) won't differ in any way.

Predicate type:

Enumerative

Parameters:

L

ID of the rectangle(s) (two rectangles may have the same ID)

X

X coordinate of rectangle's left-top corner (in pixels from the origin of V)

Y

Y coordinate of rectangle's left-top corner (in pixels from the origin of V)

L

rectangle's length (in pixels)

H

rectangle's height (in pixels)

V

ID of the view that will contain the rectangle(s)

Attributes:

RectangleColor, RectangleFrameColor

Example:

/** 
View(Out 1);
ViewOrigin(Out 12,Out 12,1);
Rectangle(Out R,Out X,Out Y,Out 13,Out 13,1)
For I:InRange(I,0,6)
For J:InRange(J,0,10)
Assign X=J*12 Y=I*12 R=I+J;
**/

"Declare view 1 having origin in (12,12). Then declare 7*11 distinct 13x13 squares forming a grid inside view 1"

The bidimensional grid is generated through nested calls to the built-in InRange enumerative predicate. Note rectangles on the same diagonal have the same ID equal to the sum of their row and column position.

This example yields the following result:

RectangleColor(R,Out C,V)

Declare the filling color C of rectangles having ID equal to R in the view V

Description:

The visualization system calls this predicate to gather the filling color of all rectangles having ID equal to R in the view V.

Default:

If RectangleColor is not declared or is false for a given rectangle, the default color is No_Color, which means the rectangle is outlined but not filled.

Predicate type:

Single value

Parameters:

R

ID of the rectangle(s) we are explicitly giving a fillling color

C

filling color of the rectangle(s) with ID equal to R in the view V

V

ID of the view that contains the rectangle(s)

Example:

/** RectangleColor(R,Out C,1) Assign C=R%4; **/

"Declare the filling color of rectangles having ID equal to R in the view 1 to be R modulo 4"

The following result is obtained by adding the code above to the example given for Rectangle (notice that the color of rectangles on the same diagonal is the same, since they have the same ID that is used as a color index modulo 4):

RectangleFrameColor(R,Out C,V)

Declare the frame color C of rectangles having ID equal to R in the view V

Description:

The visualization system calls this predicate to gather the frame color of all rectangles having ID equal to R in the view V.

Default:

If RectangleFrameColor is not declared or is false for a given rectangle, the default color is Grey.

Predicate type:

Single value

Parameters:

R

ID of the rectangle(s) we are explicitly giving a frame color

C

frame color of the rectangle(s) with ID equal to R in the view V

V

ID of the view that contains the rectangle(s)

Example:

/** RectangleFrameColor(_,Out White,1); **/

"Declare the frame color of rectangles having any ID in the view 1 to be White"

Note the use of the underscore "_" as a wild card is for reinforcing intuition, but any other valid C identifier might be used.

The following result is obtained by adding the code above to the examples given for Rectangle and RectangleColor:

Ellipse(Out E,Out X,Out Y,Out L,Out H,V)

Declare ellipses in the view V by enumeration

Description:

The visualization system repeatedly calls this predicate for each view V to gather information (ID, position and size) about ellipses to be drawn inside it.

Each ellipse must be assigned an ID number that will be used to declare its attributes. Note if two ellipses are given the same ID their attributes (color, framecolor) won't differ in any way.

Predicate type:

Enumerative

Parameters:

E

ID of the ellipse(s) (two ellipses may have the same ID)

X

X coordinate of enclosing rectangle's left-top corner (in pixels from the origin of V)

Y

Y coordinate of enclosing rectangle's left-top corner (in pixels from the origin of V)

L

length of enclosing rectangle (in pixels)

H

height of enclosing rectangle (in pixels)

V

ID of the view that will contain the ellipse(s)

Attributes:

EllipseColor, EllipseFrameColor

Example:

/**
View(Out 1);
Ellipse(Out E,Out X,Out Y,Out 60,Out 50,1)
For N:InRange(N,0,2)
Assign E=1 X=10+N*40 Y=10
Moreover
For N:InRange(N,0,1)
Assign E=2 X=30+N*40 Y=40;
**/

or, equivalently:

/** 
View(Out 1);
Ellipse(Out 1,Out X,Out 10,Out 60,Out 50,1)
For N:InRange(N,0,2) Assign X=10+N*40;
Ellipse(Out 2,Out X,Out 40,Out 60,Out 50,1)
Assign X=30 Moreover
Assign X=70;
**/

"Declare view 1. Then declare two sets of ellipses, one having ID 1 and containing three elements, and the other having ID 2 and containing two elements"

This example yields the following result:

EllipseColor(E,Out C,V)

Declare the filling color C of ellipses having ID equal to E in the view V

Description:

The visualization system calls this predicate to gather the filling color of all ellipses having ID equal to E in the view V.

Default:

If EllipseColor is not declared or is false for a given ellipse, the default color is No_Color, which means that the ellipse is outlined but not filled.

Predicate type:

Single value

Parameters:

E

ID of the ellipse(s) we are explicitly giving a fillling color

C

filling color of the ellipse(s) with ID equal to E in the view V

V

ID of the view that contains the ellipse(s)

Example:

/** 
EllipseColor(1,Out LightGreen,1);
EllipseColor(2,Out Green,1);
**/

"Declare the filling color of ellipses with ID=1 in the view 1 to be LightGreen. If ID=2 the declared color is Green"

The following result is obtained by adding the code above to the example given for Ellipse:

EllipseFrameColor(E,Out C,V)

Declare the frame color C of ellipses having ID equal to E in the view V

Description:

The visualization system calls this predicate to gather the frame color of all ellipses having ID equal to E in the view V.

Default:

If EllipseFrameColor is not declared or is false for a given ellipse, the default color is Grey.

Predicate type:

Single value

Parameters:

E

ID of the ellipse(s) we are explicitly giving a frame color

C

frame color of the ellipse(s) with ID equal to E in the view V

V

ID of the view that contains the ellipse(s)

Example:

/** 
EllipseFrameColor(1,Out Red,1);
EllipseFrameColor(2,Out Blue,1);
**/

or, equivalently:

/**
EllipseFrameColor(E,Out C,1)
If E==1 Assign C=Red Moreover
If E==2 Assign C=Blue;
**/

"Declare the frame color of ellipses having ID=1 in the view 1 to be Red, and those with ID=2 to be Blue"

The following result is obtained by adding the code above to the example given for Ellipse:

SmallText(Out S,Out X,Out Y,Out T,Out L,Out A,V)

Declare static text fields in the view V by enumeration

Description:

The visualization system repeatedly calls this predicate for each view V to gather information (ID, position, type, value and alignment) about static text fields to be drawn inside it.

Each static text field must be assigned an ID number that will be used to declare its attributes. Note if two static text fields are given the same ID their attributes (color, size, font, face) won't differ in any way.

Predicate type:

Enumerative

Parameters:

S

ID of the static text field(s) (two static text fields may have the same ID)

X

X coordinate of field (in pixels from the origin of V), according to the alignment declared in A

Y

Y coordinate of field's baseline (in pixels from the origin of V)

T

type of parameter L (Void, Int, Char or String)

L

value to be shown into the static text field, according to the value of T:

T=Void

L is ignored and the text field is empty

T=Int

the text field shows L as an integer value

T=Char

the text field shows least significant byte of L as a character value

T=String

the text field shows the C string pointed to by L. If L=0 then the "Nil" string is shown.

A

text alignment (Left, Center, Right) with respect to parameters X and Y as follows:

A=Left

A=Center

A=Right

V

ID of the view that will contain the static text field(s)

Attributes:

SmallTextColor, SmallTextSize, SmallTextFont,SmallTextFace

Example:

/** 
View(Out 1);
SmallText(Out N,Out X,Out Y,Out Char,Out L,Out Right,1)
For N:InRange(N,'!','~')
Assign K=N-'!' X=20+K/16*50 Y=20+K%16*14 L=N;
SmallText(Out N,Out X,Out Y,Out Int,Out L,Out Left,1)
For N:InRange(N,'!','~')
Assign K=N-'!' X=28+K/16*50 Y=20+K%16*14 L=N;
**/

"Declare view 1. Then declare 2*93 static text fields showing all pairs <character,ASCII code> from 33 to 126. Each pair of static text fields has ID equal to the corresponding ASCII code"

The first elements of a pair are enumerated by the first instance of the SmallText predicate, while the second elements by the second instance. Note items are shown as a table with 16 rows and 93/16=6 columns, items in a pair have different alignment and their relative distance is 8 pixels.

This example yields the following result:

 

SmallTextColor(S,Out C,V)

Declare the color C of static text fields having ID equal to S in the view V

Description:

The visualization system calls this predicate to gather the color of all static text fields having ID equal to S in the view V.

Default:

If SmallTextColor is not declared or is false for a given static text field, the default color is Grey.

Predicate type:

Single value

Parameters:

S

ID of the static text field we are explicitly giving a color

C

color of the static text field with ID equal to S in the view V

V

ID of the view that contains the static text field(s)

Example:

/**
SmallTextColor(N,Out Red,1) If N>='0' && N<='9';
SmallTextColor(N,Out Green,1) If N>='A' && N<='Z';
SmallTextColor(N,Out Blue,1) If N>='a' && N<='z';
**/

"Declare the color of any static text field having ID in the ranges ['0','9'], ['A','Z'], ['a','z'] to be respectively Red, Green and Blue. Other text fields will be Grey by default since nothing is explicitly stated about them"

The following result is obtained by adding the code above to the example given for SmallText:

 

SmallTextSize(F,Out S,V)

Declare the font size S of static text fields having ID equal to F in the view V

Description:

The visualization system calls this predicate to gather the font size of all static text fields having ID equal to F in the view V.

Default:

If SmallTextSize is not declared or is false for a given static text field, the default font size is 10 pt.

Predicate type:

Single value

Parameters:

F

ID of the static text field we are explicitly giving a font size

S

font size (in pt) of the static text field with ID equal to F in the view V

V

ID of the view that contains the static text field(s)

Example:

/**
SmallText(Out 1,Out 10,Out 80,Out String,Out S,Out Left,1)
Assign S="Bach";
SmallTextSize(1,Out 80,1);
**/

"Declare a static text field containing a C string. Then declare that its size is 80 pt"

This example yields the following result:

SmallTextFont(S,Out F,V)

Declare the font F of static text fields having ID equal to S in the view V

Description:

The visualization system calls this predicate to gather the font of all static text fields having ID equal to S in the view V.

Default:

If SmallTextFont is not declared or is false for a given static text field, the default font is Geneva.

Predicate type:

Single value

Parameters:

S

ID of the static text field we are explicitly giving a font

F

font of the static text field with ID equal to S in the view V

V

ID of the view that contains the static text field(s)

Example:

/** SmallTextFont(1,Out Symbol,1); **/

"Declare the font of any static text field having ID 1 to be Symbol"

The following result is obtained by adding the code above to the example given for SmallTextSize:

SmallTextFace(S,Out F,V)

Declare the face F of static text fields having ID equal to S in the view V

Description:

The visualization system calls this predicate to gather the face of all static text fields having ID equal to S in the view V.

Default:

If SmallTextFace is not declared or is false for a given static text field, the default face is Normal.

Predicate type:

Single value

Parameters:

S

ID of the static text field we are explicitly giving a face

F

face of the static text field with ID equal to S in the view V. The face number may be obtained as a sum of constants: e.g. Italic+Outline

V

ID of the view that contains the static text field(s)

Example:

/** 
HasDivisor(N) For K:InRange(K,2,N/2) If N%K==0;
Prime(N) If !HasDivisor(N);
SmallTextColor(N,Out Blue,1) If Prime(N);
SmallTextFace(N,Out Bold+Underline,1) If Prime(N);
**/

"Declare user predicates HasDivisor and Prime: the first checks if a given integer has any divisor, the second checks if a given number is a prime number. Then declare color=Blue and face=Bold+Underline for any text field having prime ID."

The following result is obtained by adding the code above to the example given for SmallText: