This file contains procedures for drawing on the EV3 screen.
![]()  | MODULE_SCREEN | 2 | 
| SCREEN_WIDTH | 178 | 
| SCREEN_HEIGHT | 128 | 
| SCREEN_CENTER_X | 90 | 
| SCREEN_CENTER_Y | 64 | 
| SCREEN_UPDATE | 0 | 
| SCREEN_CLEAR | 1 | 
| SCREEN_FILL | 2 | 
| SCREEN_FILL_COLOR | 3 | 
| SCREEN_TEXT_SIZE | 4 | 
| SCREEN_TEXT_ALIGN | 5 | 
| SCREEN_DRAW_PIXEL | 6 | 
| SCREEN_DRAW_NUMBER | 7 | 
| SCREEN_DRAW_TEXT | 8 | 
| SCREEN_DRAW_LINE | 9 | 
| SCREEN_DRAW_RECT | 10 | 
| SCREEN_DRAW_CIRCLE | 11 | 
| SCREEN_DRAW_IMAGE | 12 | 
| WHITE | 0 | 
| BLACK | 1 | 
| TEXT_SIZE_1 | 0 | 
| TEXT_SIZE_2 | 1 | 
| TEXT_SIZE_3 | 2 | 
| TEXT_ALIGN_LEFT | 0 | 
| TEXT_ALIGN_CENTER | 1 | 
| TEXT_ALIGN_RIGHT | 2 | 
Update the screen.
proc updateScreen()
Clear the entire screen.
proc clearScreen()
Enable or disable filling, used for drawing rectangles or circles.
proc setFill(number fill)
| Name | Type | Description | 
|---|---|---|
| fill | number | Enable or disable: TRUE or FALSE. | 
Set the fill color.
proc setFillColor(number fillColor)
| Name | Type | Description | 
|---|---|---|
| fillColor | number | The color: WHITE or WHITE | 
Set the text size.
proc setTextSize(number textSize)
| Name | Type | Description | 
|---|---|---|
| textSize | number | The size: TEXT_SIZE_1, TEXT_SIZE_2 or TEXT_SIZE_3. | 
Set the text alignment.
proc setTextAlign(number textAlign)
| Name | Type | Description | 
|---|---|---|
| textAlign | number | The size: TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER or TEXT_ALIGN_RIGHT. | 
Draw a pixel with the current fill color.
proc drawPixel(number x, number y)
| Name | Type | Description | 
|---|---|---|
| x | number | The x coordinate, a value equal or greater than 0 and less than 178, values out of range are ignored. | 
| y | number | The y coordinate, a value equal or greater than 0 and less than 128, values out of range are ignored. | 
The following demo draws black and white pixels:
"Pixel demo" "lib/modules/standard.whl" "lib/modules/screen.whl" proc main() ; Fill half the screen black... setFill(TRUE) setFillColor(BLACK) drawRect(0, 0, 89, 128) number s number x, y = 0 setFillColor(WHITE) s = 1 while y < 128 ; Draw a line with white pixels... setFillColor(WHITE) for x = 0 to 89 step 2 drawPixel(x, y) end ; Draw a line with black pixels... setFillColor(BLACK) for x = 90 to 178 step 2 drawPixel(x, y) end y += s s += 1 end ; Wait... halt() end
Draw number with the current fill color.
proc drawNumber(number x, number y, number n)
| Name | Type | Description | 
|---|---|---|
| x | number | The x coordinate. | 
| y | number | The y coordinate. | 
| n | number | 
Draw a text with the active fill and color settings.
"lib/modules/standard.whl" "lib/modules/screen.whl" proc main() number n for n = 0 to 10 number x number y x = n x *= 10 y = n y *= 4 y += 10 drawNumber(x, y, n) end halt() end Draw a text with the active fill and color settings. "lib/modules/standard.whl" "lib/modules/screen.whl" proc main() ; Draw a small black text at the left top of the screen... drawText(10, 10, "The quick brown") ; Set the text size to small bold: setTextSize(1) drawText(10, 25, "fox jumped over") ; Set the text size to large: setTextSize(2) drawText(10, 40, "Lazy dogs") ; Set the text size back to small: setTextSize(0) ; Set the fill: setFill(1) ; This draws small text with black bagkround... drawText(10, 60, "The quick brown") halt() end
Draw text with the current fill color.
proc drawText(number x, number y, string s)
| Name | Type | Description | 
|---|---|---|
| x | number | The x coordinate. | 
| y | number | The y coordinate. | 
| s | string | 
Draw line with the current fill color.
proc drawLine(number x1, number y1, number x2, number y2)
| Name | Type | Description | 
|---|---|---|
| x1 | number | The x coordinate of the start point. | 
| y1 | number | The y coordinate of the start point. | 
| x2 | number | The x coordinate of the end point. | 
| y2 | number | The y coordinate of the end point. | 
The following demo creates black and white lines:
"Line demo" "lib/modules/standard.whl" "lib/modules/screen.whl" proc main() ; Fill half the screen black... setFill(TRUE) setFillColor(BLACK) drawRect(0, 0, 89, 128) number y ; Daw white lines from the center of the screen to the left side... setFillColor(WHITE) for y = 0 to 128 step 8 drawLine(0, y, 89, 64) end ; Daw black lines from the center of the screen to the right side... setFillColor(BLACK) for y = 0 to 128 step 8 drawLine(177, y, 90, 64) end ; Wait... halt() end
Draw rectange with the current fill color and fill setting.
proc drawRect(number x, number y, number width, number height)
| Name | Type | Description | 
|---|---|---|
| x | number | The x left position of the rectangle. | 
| y | number | The y top position of the rectangle. | 
| width | number | The width. | 
| height | number | The height. | 
The following demo draws black and white rectangles with and without a border:
"Rectangle demo" "lib/modules/standard.whl" "lib/modules/screen.whl" proc main() ; Draw two black filled rectangles at the left/top and right/bottom... setFill(TRUE) setFillColor(BLACK) drawRect(0, 0, 89, 64) drawRect(89, 64, 89, 64) ; Draw a white line rectangle at the left/top... setFill(FALSE) setFillColor(WHITE) drawRect(10, 10, 69, 44) ; Draw a white filled rectangle at the right/bottom... setFill(TRUE) drawRect(99, 74, 69, 44) ; Draw a black filled rectangle at the right/top... setFillColor(BLACK) drawRect(99, 10, 69, 44) ; Draw a black line rectangle at the left/bottom... setFill(FALSE) drawRect(10, 74, 69, 44) ; Wait... halt() end
Draw circle with the current fill color and fill setting.
proc drawCircle(number x, number y, number radius)
| Name | Type | Description | 
|---|---|---|
| x | number | The x horizontal center of the circle. | 
| y | number | The y vertical center of the circle. | 
| radius | number | The radius. | 
The following demo draws black and white circles with and without a border:
"Circle demo" "lib/modules/standard.whl" "lib/modules/screen.whl" proc main() ; Draw two black filled rectangles at the left/top and right/bottom... setFill(TRUE) setFillColor(BLACK) drawRect(0, 0, 89, 64) drawRect(89, 64, 89, 64) ; Draw a white line circle at the left/top... setFill(FALSE) setFillColor(WHITE) drawCircle(45, 32, 24) ; Draw a white filled circle at the right/bottom... setFill(TRUE) drawCircle(134, 96, 24) ; Draw a black filled circle at the right/top... setFillColor(BLACK) drawCircle(134, 32, 24) ; Draw a black line circle at the left/bottom... setFill(FALSE) drawCircle(45, 96, 24) ; Wait... halt() end
Draw an image.
proc drawImage(number x, number y, string filename)
| Name | Type | Description | 
|---|---|---|
| x | number | The x left position. | 
| y | number | The y top position. | 
| filename | string | The filename, should have an .rgf extension. | 
"lib/modules/standard.whl" "lib/modules/screen.whl" "test.rgf" "011111110" "100000001" "101000101" "100101001" "100010001" "100101001" "101000101" "100000001" "011111110" proc main() drawImage(25, 25, "test.rgf") halt() end