The Graphics class allows you to draw graphics in PRIMER. More...
The PRIMER JavaScript API provides many class constants, properties and methods. For Arup to
be able to extend and enhance the API in the future any constant, property or method names beginning with a lowercase
or uppercase letter are reserved.
If you need to add your own properties or methods to one of the existing classes then to avoid any potential future conflict you
should ensure that the name begins with either an underscore (_) or a dollar sign ($) or the name is prefixed with your
own unique identifier.
For example if company 'ABC' need to add a property called 'example' then to avoid any potential future conflict use one of:
| Name | Description |
| Graphics.CIRCLE | Circle shape. See Graphics.Shape() for use. |
| Graphics.DASHDOT_LINE | Dashed and dotted lines. See Graphics.LineStyle() for use. |
| Graphics.DASH_LINE | Dashed lines. See Graphics.LineStyle() for use. |
| Graphics.DIAMOND | Diamond shape. See Graphics.Shape() for use. |
| Graphics.DOT_LINE | Dotted lines. See Graphics.LineStyle() for use. |
| Graphics.FILLED_CIRCLE | Filled circle shape. See Graphics.Shape() for use. |
| Graphics.FILLED_DIAMOND | Filled diamond shape. See Graphics.Shape() for use. |
| Graphics.FILLED_HOURGLASS | Filled hourglass shape. See Graphics.Shape() for use. |
| Graphics.FILLED_SQUARE | Filled square shape. See Graphics.Shape() for use. |
| Graphics.HOURGLASS | Hourglass shape. See Graphics.Shape() for use. |
| Graphics.POINT | Point shape. See Graphics.Shape() for use. |
| Graphics.SOLID_LINE | Solid lines. See Graphics.LineStyle() for use. |
| Graphics.SQUARE | Square shape. See Graphics.Shape() for use. |
Graphics.Start(); Graphics.LineWidth(3); Graphics.LineColour(Colour.RED); Graphics.LineStyle(Graphics.SOLID_LINE); Graphics.Line(0, 0, 0, 10, 20, 30); Graphics.Finish();
The drawing commands must be between
Graphics.Start()
and
Graphics.Finish()
or else nothing will be seen. This is suitable for sketching but the line will disappear if the graphics are redrawn or any dynamic viewing is done. To draw graphics which will stay on the screen even if dynamic viewing or a redraw is done you have to register a function using Graphics.DrawingFunction() which will be called every time the graphics are redrawn by PRIMER. e.g:
var w = new Window("Graphics test", 0.8, 1.0, 0.5, 0.6);
var e = new Widget(w, Widget.BUTTON, 1, 21, 1, 7, "Exit");
e.onClick = Exit;
do_draw();
Graphics.DrawingFunction(do_draw);
w.Show();
////////////////////////////////////////////////////////////////////////////////
function do_draw()
{
Graphics.Start();
Graphics.LineWidth(3);
Graphics.LineColour(Colour.RED);
Graphics.LineStyle(Graphics.SOLID_LINE);
Graphics.Line(0, 0, 0, 10, 20, 30);
Graphics.Finish();
}See the documentation below for more details.
Whether depth testing (hidden surface removal) is performed (true) or not (false)
ReturnsNo return value |
ExampleTo turn off depth testing: Graphics.DepthTest(false); To turn depth testing back on: Graphics.DepthTest(true);
|
DrawingFunction(name[function]) [static]DescriptionSet the function to draw graphics from javaScript. This function
will be called each time the graphics are redrawn after PRIMER has finished
drawing everything else. This allows you to add extra items to the graphics. |
The name of the function (or null to remove a function)
ReturnsNo return value |
ExampleTo set function MyRedrawFunction as the Graphics drawing function Graphics.DrawingFunction(MyRedrawFunction);
|
FillColour(colour[Colour]) [static]DescriptionSets the colour for drawing polygons. See the Colour class for more details on colours. |
The colour you want to fill polygons with
ReturnsNo return value |
ExampleTo Set the current fill colour to red: Graphics.FillColour(Colour.RED); or Graphics.FillColour( Colour.RGB(255, 0, 0) );
|
Finish() [static]DescriptionFinish any graphics. See also Graphics.Start(). This must be used to finish drawing. |
No arguments
ReturnsNo return value |
ExampleTo finish any graphics operations: Graphics.Finish();
|
Line(x1[real], y1[real], z1[real], x2[real], y2[real], z2[real]) [static]DescriptionDraws a line from (x1, y1, z1) to (x2, y2, z2). See also Graphics.LineTo() and Graphics.MoveTo() |
X coordinate of point 1
Y coordinate of point 1
Z coordinate of point 1
X coordinate of point 2
Y coordinate of point 2
Z coordinate of point 2
ReturnsNo return value |
ExampleTo draw a line from (0.0, 0.0, 0.0) to (10.0, 20.0, 30.0) Graphics.Line(0.0, 0.0, 0.0, 10.0, 20.0, 30.0);
|
LineColour(colour[Colour]) [static]DescriptionSets the colour for drawing lines. See the Colour class for more details on colours. |
The colour you want to draw lines with
ReturnsNo return value |
ExampleTo Set the current drawing colour to red: Graphics.LineColour(Colour.RED); or Graphics.LineColour( Colour.RGB(255, 0, 0) );
|
LineStyle(style[constant]) [static]DescriptionSets the style for drawing lines. |
The style to draw lines with. Can be: Graphics.SOLID_LINE, Graphics.DASH_LINE, Graphics.DASHDOT_LINE or Graphics.DOT_LINE
ReturnsNo return value |
ExampleTo Set the current line style to 3: Graphics.LineStyle(3);
|
LineTo(x[real], y[real], z[real]) [static]DescriptionDraws a line from the current point to (x, y, z). After drawing the line the current point will be (x, y, z). See also Graphics.Line() and Graphics.MoveTo() |
X coordinate
Y coordinate
Z coordinate
ReturnsNo return value |
ExampleTo draw a line from the current point to (10.0, 20.0, 30.0): Graphics.LineTo(10.0, 20.0, 30.0);
|
LineWidth(width[Integer]) [static]DescriptionSets the width for drawing lines. |
The width to draw lines with
ReturnsNo return value |
ExampleTo Set the current line width to 3: Graphics.LineWidth(3);
|
MoveTo(x[real], y[real], z[real]) [static]DescriptionSets the current point to (x, y, z). See also Graphics.Line() and Graphics.LineTo() |
X coordinate
Y coordinate
Z coordinate
ReturnsNo return value |
ExampleTo set the current point to (10.0, 20.0, 30.0): Graphics.MoveTo(10.0, 20.0, 30.0);
|
PolygonFinish() [static]DescriptionEnds drawing a polygon. See also Graphics.PolygonStart() |
No arguments
ReturnsNo return value |
PolygonStart() [static]DescriptionStarts drawing a convexpolygon. A maximum of 250 vertices are allowed.
Drawing concave polygons is not supported by this function. To draw concave polygons split them into separate convex polygons. |
No arguments
ReturnsNo return value |
Shape(shape[constant], size[integer]) [static]DescriptionDraws a simple shape. |
The style to draw lines with. Can be: Graphics.POINT, Graphics.SQUARE, Graphics.CIRCLE, Graphics.DIAMOND, Graphics.HOURGLASS, Graphics.FILLED_SQUARE, Graphics.FILLED_CIRCLE, Graphics.FILLED_DIAMOND or Graphics.FILLED_HOURGLASS
Size the shape should be drawn at.
ReturnsNo return value |
ExampleTo draw a filled square at (10, 20, 30) at size 10: Graphics.MoveTo(10, 20, 30); Graphics.Shape(Graphics.FILLED_SQUARE, 10);
|
Start() [static]DescriptionStart any graphics. See also Graphics.Finish(). This must be used before any drawing is done. |
No arguments
ReturnsNo return value |
ExampleTo start drawing graphics: Graphics.Start();
|
Text(text[String]) [static]DescriptionDraws text at current position. See Graphics.MoveTo() to set the current position. |
The text to write
ReturnsNo return value |
ExampleTo write "Example" at (10, 20, 30): Graphics.MoveTo(10, 20, 30);
Graphics.Text("Example");
|
TextColour(colour[Colour]) [static]DescriptionSets the colour for drawing text. See the Colour class for more details on colours. |
The colour you want to draw text with
ReturnsNo return value |
ExampleTo Set the current text drawing colour to red: Graphics.TextColour(Colour.RED); or Graphics.TextColour( Colour.RGB(255, 0, 0) );
|
TextSize(size[Integer]) [static]DescriptionSets the size for drawing text. |
The size to draw text with
ReturnsNo return value |
ExampleTo Set the current text size to 30: Graphics.TextSize(30);
|