Wheel IDE

Online demo »

Screen

This file contains procedures for drawing on the EV3 screen.

Constants

The screen module.
Source: lib/modules/screen.whl, line: 10
MODULE_SCREEN2

Screen size informtion.
Source: lib/modules/screen.whl, line: 13
SCREEN_WIDTH178
SCREEN_HEIGHT128
SCREEN_CENTER_X90
SCREEN_CENTER_Y64

Module calls to draw on the screen.
Source: lib/modules/screen.whl, line: 19
SCREEN_UPDATE0
SCREEN_CLEAR1
SCREEN_FILL2
SCREEN_FILL_COLOR3
SCREEN_TEXT_SIZE4
SCREEN_TEXT_ALIGN5
SCREEN_DRAW_PIXEL6
SCREEN_DRAW_NUMBER7
SCREEN_DRAW_TEXT8
SCREEN_DRAW_LINE9
SCREEN_DRAW_RECT10
SCREEN_DRAW_CIRCLE11
SCREEN_DRAW_IMAGE12

The two colors.
Source: lib/modules/screen.whl, line: 34
WHITE0
BLACK1

There are three text sizes supported.
Source: lib/modules/screen.whl, line: 38
TEXT_SIZE_10
TEXT_SIZE_21
TEXT_SIZE_32

Text alignment options.
Source: lib/modules/screen.whl, line: 43
TEXT_ALIGN_LEFT0
TEXT_ALIGN_CENTER1
TEXT_ALIGN_RIGHT2

Procedures

updateScreen
Source: lib/modules/screen.whl, line: 48

Update the screen.

proc updateScreen()

clearScreen
Source: lib/modules/screen.whl, line: 53

Clear the entire screen.

proc clearScreen()

setFill
Source: lib/modules/screen.whl, line: 58

Enable or disable filling, used for drawing rectangles or circles.

proc setFill(number fill)
Parameters:
NameTypeDescription
fillnumberEnable or disable: TRUE or FALSE.

setFillColor
Source: lib/modules/screen.whl, line: 65

Set the fill color.

proc setFillColor(number fillColor)
Parameters:
NameTypeDescription
fillColornumberThe color: WHITE or WHITE

setTextSize
Source: lib/modules/screen.whl, line: 72

Set the text size.

proc setTextSize(number textSize)
Parameters:
NameTypeDescription
textSizenumberThe size: TEXT_SIZE_1, TEXT_SIZE_2 or TEXT_SIZE_3.

setTextAlign
Source: lib/modules/screen.whl, line: 79

Set the text alignment.

proc setTextAlign(number textAlign)
Parameters:
NameTypeDescription
textAlignnumberThe size: TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER or TEXT_ALIGN_RIGHT.

drawPixel
Source: lib/modules/screen.whl, line: 86

Draw a pixel with the current fill color.

proc drawPixel(number x, number y)
Parameters:
NameTypeDescription
xnumberThe x coordinate, a value equal or greater than 0 and less than 178, values out of range are ignored.
ynumberThe 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:


#project "Pixel demo"

#include "lib/modules/standard.whl"
#include "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

drawNumber
Source: lib/modules/screen.whl, line: 94

Draw number with the current fill color.

proc drawNumber(number x, number y, number n)
Parameters:
NameTypeDescription
xnumberThe x coordinate.
ynumberThe y coordinate.
nnumber

Draw a text with the active fill and color settings.

#include "lib/modules/standard.whl"
#include "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.

#include "lib/modules/standard.whl"
#include "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

drawText
Source: lib/modules/screen.whl, line: 102

Draw text with the current fill color.

proc drawText(number x, number y, string s)
Parameters:
NameTypeDescription
xnumberThe x coordinate.
ynumberThe y coordinate.
sstring

drawLine
Source: lib/modules/screen.whl, line: 110

Draw line with the current fill color.

proc drawLine(number x1, number y1, number x2, number y2)
Parameters:
NameTypeDescription
x1numberThe x coordinate of the start point.
y1numberThe y coordinate of the start point.
x2numberThe x coordinate of the end point.
y2numberThe y coordinate of the end point.

The following demo creates black and white lines:


#project "Line demo"

#include "lib/modules/standard.whl"
#include "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

drawRect
Source: lib/modules/screen.whl, line: 120

Draw rectange with the current fill color and fill setting.

proc drawRect(number x, number y, number width, number height)
Parameters:
NameTypeDescription
xnumberThe x left position of the rectangle.
ynumberThe y top position of the rectangle.
widthnumberThe width.
heightnumberThe height.

The following demo draws black and white rectangles with and without a border:


#project "Rectangle demo"

#include "lib/modules/standard.whl"
#include "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

drawCircle
Source: lib/modules/screen.whl, line: 130

Draw circle with the current fill color and fill setting.

proc drawCircle(number x, number y, number radius)
Parameters:
NameTypeDescription
xnumberThe x horizontal center of the circle.
ynumberThe y vertical center of the circle.
radiusnumberThe radius.

The following demo draws black and white circles with and without a border:


#project "Circle demo"

#include "lib/modules/standard.whl"
#include "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

drawImage
Source: lib/modules/screen.whl, line: 139

Draw an image.

proc drawImage(number x, number y, string filename)
Parameters:
NameTypeDescription
xnumberThe x left position.
ynumberThe y top position.
filenamestringThe filename, should have an .rgf extension.
#include "lib/modules/standard.whl"
#include "lib/modules/screen.whl"

#image "test.rgf"
#data  "011111110"
#data  "100000001"
#data  "101000101"
#data  "100101001"
#data  "100010001"
#data  "100101001"
#data  "101000101"
#data  "100000001"
#data  "011111110"

proc main()
    drawImage(25, 25, "test.rgf")
    halt()
end