Class «display»

This article is automatically translated from Russian by Google Translator.

Provides access to the display of the robot.

Screen size: 240*320 pixels.

addLabel

Print the specified text on the screen, starting from the specified coordinate. If there was already text in the specified coordinates, it will be replaced by the new text.

The changes on the display will occur only after calling the method "redraw".

brick.display().addLabel("text", x, y);

Parameters:

  • text — display text,

  • x, y — screen coordinates.

Example

brick.display().addLabel('Hello, world!', 1, 1);

clear

Clear the drawing window.

brick.display().clear();

drawArc

Draw an arc of an ellipse inscribed into a rectangle with the upper left corner at specified coordinates and having a given width and height. The changes on the display will occur only after calling the method "redraw".

brick.display().drawArc(x, y, l, h, from, to);

Parameters:

  • x, y — the coordinates of the upper left corner of the rectangle on the screen,

  • l — rectangle width,

  • h — rectangle height,

  • from — initial angle bounding the arc,

  • to — finite angle bounding the arc.

Example

brick.display().drawArc(0, 0, 10, 10, 20, 50);

drawEllipse

Draw an ellipse inscribed into a rectangle with the upper left corner at specified coordinates and having a given width and height. The changes on the display will occur only after calling the method "redraw".

brick.display().drawEllipse(x, y, l, h);

Parameters:

  • x, y — coordinates of the upper left corner of the rectangle,

  • l — rectangle width,

  • h — rectangle height.

Example

brick.display().drawEllipse(0, 0, 10, 10);

drawLine

Draw a line with the beginning and the end at the given coordinates. The changes on the display will occur only after calling the method "redraw".

brick.display().drawLine(x0, y0, x1, y1);

Parameters:

  • x0, y0 — line origin coordinates,

  • x1, y1 — line end coordinates.

Example

brick.display().drawLine(0, 0, 10, 10);

drawPoint

Draw a point at given coordinates. The changes on the display will occur only after calling the method "redraw".

brick.display().drawPoint(x, y);

Parameters:

  • point coordinates x, y.

Example

brick.display().drawPoint(10, 10);

drawRect

Draw a rectangle with the upper left corner at the specified coordinates and having the specified width and height. The changes on the display will occur only after calling the method "redraw".

brick.display().drawRect(x, y, l, h);

Parameters:

  • x, y — coordinates of the upper left corner of the rectangle,

  • l — rectangle width,

  • h — rectangle height.

Example

brick.display().drawRect(0, 0, 10, 10);

hide

Close and clear the drawing window.

brick.display().hide();

redraw

Redraw the window to draw. The changes to the display will only happen after this method is called.

brick.display().redraw();

removeLabels

Remove from the screen all text added to it by calls to the "addLabel" method.

brick.display().removeLabels();

setBackground

Set the screen background to the color you specify.

Available colors:

  • white,

  • red, darkRed,

  • green, darkGreen,

  • blue, darkBlue,

  • cyan, darkCyan,

  • magenta, darkMagenta,

  • yellow, darkYellow,

  • gray, darkGray, lightGray,

  • black.

brick.display().setBackground("color");

As a parameter, you must specify the color.

Example

brick.display().setBackground("red");

setPainterColor

Set the color of the brush used to draw the graphical primitives.

Available colors:

  • white,

  • red, darkRed,

  • green, darkGreen,

  • blue, darkBlue,

  • cyan, darkCyan,

  • magenta, darkMagenta,

  • yellow, darkYellow,

  • gray, darkGray, lightGray,

  • black.

brick.display().setPainterColor("color");

As a parameter, you must specify the color.

Example

brick.display().setPainterColor("red");

setPainterWidth

Set the thickness of the brush used to draw the graphical primitives, in pixels.

brick.display().setPainterWidth(d);

As a parameter, you must specify the thickness d.

Example

brick.display().setPainterWidth(5);

show

Display the image generated in the one-dimensional array on the controller.

brick.display().show(array, width, height, format)

Parameters:

  • array — a one-dimensional integer array with dimensions width×height

  • width и height — the width and height of the image, respectively

  • The format in which each element of the array is represented should be passed as the format parameter. The formats currently supported are: «rgb32», «grayscale8», «rgb888».

Example

Examples of using show() on an image taken withgetPhoto().

//rgb32
var photo = getPhoto();
brick.display().show(photo, 160, 120, "rgb32");
script.wait(5000);

//rgb888
pic = []
photo = getPhoto();
l = photo.length;
for (i = 0; i < l; i++) {
    var p = photo[i];
    pic.push((p&0xff0000)>>16);
    pic.push((p&0xff00)>>8);
    pic.push((p&0xff));
}
brick.display().show(pic, 160, 120, "rgb888");
script.wait(5000);                            

//grayscale8                                   
pic = []                                      
photo = getPhoto();
l = photo.length;                             
for (i = 0; i < l; i++) {                     
        var p = photo[i];                     
        pic.push(((p&0xff0000)>>18) + ((p&0xff00)>>10) + ((p&0xff)>>2));                
}                                             
                                              
brick.display().show(pic, 160, 120, "grayscale8");
script.wait(5000);

showImage

Display the image previously loaded on the robot.

brick.display().showImage("imagePath");

The name of the image file (in BMP, GIF, JPG, JPEG, PNG, PBM, PGM, PPM, TIFF, XBM, XPM formats) must be specified as a parameter, the path is specified either as absolute or relative to the trik folder.

Example

brick.display().showImage("media/trik_smile_sad.png");

Last updated