Drawing API

The API lesson shows the available core methods, including Print(). To give you more power, the BrainPad API gives you full access to the display/LED-matrix. This is nice to have in most cases and become a requirement in some, like when creating a video game.

Graphical Memory

On computer systems, it is standard to handle all the “drawing” in memory, not on the display/monitor. Only when drawing elements of the memory is done then the memory is transferred to the display as a whole. Similar to the way our own brain works. We think about what we’re going to draw in our mind and then we draw it.

Even when clearing the screen, Clear() will only clear the graphics memory internally. This has no effect on the display. But then Show() will transfer whatever is in the graphical memory to the screen. Note how Print() just works and just updates the screen, this is because of extra code built in to the Print() method, but then Print() is very slow. Once you have decided you will use the display API on this page, you should not use Print().

X and Y coordinates

X and Y coordinates inside code refers to an exact pixel location on the screen. This is often used to set the position of where something will appear on the screen. X values run left to right starting at 0, while Y values runs top to bottom also starting at 0. This means the top left X and Y coordinate is 0,0

 

Show()

This method will transfer the graphical memory to the display as explained above. All methods below only effect the graphical memory and do not effect the display at all.

Show()
Show();
Show()

Clear()

Clears the screen. Again, this clears the graphical memory and not the display. So Clear() really only clears the screen after Show().

Clear()
Show()
Clear();
Show();
Clear()
Show()

Circle()

Circle() generates a circle in memory, remember we must call Show() to actually see the circle on the display. The Circle() method requires 3 arguments an x and y position on the display, and the radius of the circle.

//Creates a circle on the display
Circle(60,32,25)
Show()
//Creates a circle on the display
Circle(60,32,25);
Show();
# Creates a large circle on the display
Circle(60,32,25)
Show()

Line()

Line() does exactly as its name suggests. It creates a line from one point to another point. The Line() method requires 4 values the x and y starting position followed by the x and y finishing position. Like all other drawing methods you’ll still need to call Show() to actually display the line on the screen.

//Creates a line from one point to another
Line(25,21,100,50)
Show()
//Creates a line from one point to another
Line(25,21,100,50);
Show();
# Creates a line from one position to another
Line(25,21,100,50)
Show()

Text()

This is similar to the basic Print() method but Text() gives you better control as to where the text is placed on the screen. The Text() method takes 3 arguments first the text to be displayed followed by its x and y location on the screen. Unlike the Print() method, you’ll have to follow the the Show() method to display.

//Displays the text at specific coordinates
Text("Hello Brain",30,30)
Show()
//Displays the text at specific coordinates
Text("Hello Brain",30,30);
Show();
# Displays the text at specific coordinates
Text("Hello Brain",30,30)
Show()

TextEx()

TextEx() method works like the Text() method except adds scaling so you can make larger text or tall skinny text. Depending on how you change the scale. The TextEx() method takes 5 arguments. The first three are exactly the same as the Text() method. The last two arguments set the scale height and scale width.

//Displays the text at specific coordinates
TextEx("Large Text",0,10,2,2)
Show()
//Displays the text at specific coordinates
TextEx("Large Text",0,10,2,2);
Show();
# Displays the text at specific coordinates
TextEx("Large Text",0,10,2,2)
Show()
Newsletter

Twitter Feed
Hot off the press!
December 19, 2019
October 11, 2019
September 26, 2019
August 23, 2019
August 7, 2019
August 5, 2019