Skip to content

Reference

Nick Donnelly edited this page Aug 25, 2021 · 14 revisions

Color & Display


getDistinctColor()

getDistinctColor() is a convenience utility to generate a set of colours that are different from each other - for example if you were drawing a graph that needed some different colours, you could obtain them from this function.

Image Minvio example CubeWave

bd.setDrawColor(bd.getDistinctColor(1, 1));
bd.drawFilledRect(50, 50, 50, 100);

bd.setDrawColor(bd.getDistinctColor(16, 0.2));
bd.drawFilledRect(100, 50, 50, 100);

getDisplaySize()

getWidth() / getHeight()

Retrieve the size of the app window.

Image Minvio example CubeWave

Point displaySize = bd.getDisplaySize();
bd.drawText("width=" + displaySize.x, 20, 40);
bd.drawText("height=" + displaySize.y, 20, 70);

The width can be retrieved on it's own:

int width = bd.getWidth();
bd.drawText("width=" + width, 20, 40);

And the height:

int height = bd.getHeight();
bd.drawText("height=" + height, 20, 40);

close()

Close the application.

bd.close();

repaint()

Repaint causes anything drawn this frame to be updated and made visible. The FPS parameter controls how long to wait until the next repaint. NOTE: this should not be required if you are using the MinvioApp.

bd.drawText("repaint", 20, 40);
bd.repaint(30);

Drawing Primitives


drawPoint()

drawPoint() - draw a pixel to the screen using the current colour.

Image Minvio example CubeWave

Point point = new Point(80, 80);

bd.drawPoint(point);
bd.drawPoint(120, 120);

drawLine()

drawPoint() - draw a 1 pixel wide line in the current draw colour.

Image Minvio example CubeWave

bd.drawLine(20, 20, 160, 160);
bd.drawLine(20.0, 100.0, 160, 160);

Two point objects can be used as the start and end of the line:

Image Minvio example CubeWave

Point p1 = new Point(10, 10);
Point p2 = new Point(100, 100);
bd.drawLine(p1, p2);

The thickness of the line can be specified:

Image Minvio example CubeWave

Point p1 = new Point(10, 10);
Point p2 = new Point(100, 100);
bd.drawLine(p1, p2, 3);

bd.drawLine(130, 60, 20, 100, 5);

drawRect()

Draw the border of a rectangle in the current draw colour.

Image Minvio example CubeWave

bd.drawRect(50, 50, 100, 100);

drawFilledRect()

Draw a solid rectangle in the current draw colour.

Image Minvio example CubeWave

bd.drawFilledRect(50, 50, 100, 100);

Text & Font

drawText()

Draw the supplied text using the current font at the specified location.

bd.drawText("Hello, world", 30, 70);

Image Minvio example CubeWave

Draw the supplied text using the current font at the specified location. This example shows how to create and apply a new font.

Font font1 = new Font("Times New Roman", Font.PLAIN, 20);
Font font2 = new Font("Menlo", Font.PLAIN, 20);

bd.setFont(font1);
bd.drawText("Hello, world", 30, 70);
bd.setFont(font2);
bd.drawText("Hello, world", 30, 100);

Image Minvio example CubeWave

Use getAvailableFontNames() to obtain a list of the names of all the current available fonts on your system.

String fonts[] = BasicDisplay.getAvailableFontNames();

Font font = new Font(fonts[fonts.length / 2], Font.PLAIN, 30);

bd.setFont(font);
bd.drawText("Hello, world", 30, 70);

You could write something like this to output all the font names to the java terminal:

String fonts[] = BasicDisplay.getAvailableFontNames();

for (String font : fonts) {
    System.out.println(font);
}

Clone this wiki locally