Drawing

Drawing Functions

drawPixel

Draws a single pixel.

name
type
default
description

x*

number

-

the x coordinate of the point

y*

number

-

the y coordinate of the point

color

string

'black'

the color to use

Returns

nothing

drawPixel(200, 100)
drawPixel(200, 100, "red")

drawLine

Draws a straight line.

name
type
default
description

x1*

number

-

the x coordinate of the start of the line

y1*

number

-

the y coordinate of the start of the line

x2*

number

-

the x coordinate of the end of the line

y2*

number

-

the y coordinate of the end of the line

color

string

'black'

the color to use

thickness

number

1

the thickness of the line

Returns

nothing

drawLine(200, 100, 600, 150)
drawLine(200, 100, 600, 150, "red")
drawLine(200, 100, 600, 150, "red", 10)

drawCircle

Draws the outline of a circle.Draws a straight line.

name
type
default
description

x*

number

-

the x coordinate of the center of the circle

y*

number

-

the y coordinate of the center of the circle

radius*

number

-

the radius of the circle

color

string

'black'

the color to use

thickness

number

1

the thickness of the edge

Returns

nothing

drawCircle(200, 100, 25)
drawCircle(200, 100, 25, "red")
drawCircle(200, 100, 25, "red", 5)

fillCircle

Draws a solid, filled-in, circle.

name
type
default
description

x*

number

-

the x coordinate of the center of the circle

y*

number

-

the y coordinate of the center of the circle

radius*

number

-

the radius of the circle

color

string

'black'

the color to use

Returns

nothing

fillCircle(200, 100, 25)
fillCircle(200, 100, 25, "red")

drawEllipse

Draws the outline of an ellipse.

name
type
default
description

x*

number

-

the x coordinate of the center of the ellipse

y*

number

-

the y coordinate of the center of the ellipse

width*

number

-

the width of the ellipse

height*

number

-

the height of the ellipse

color

string

'black'

the color to use

thickness

number

1

the thickness of the edge

Returns

nothing

drawEllipse(200, 100, 50, 25)
drawEllipse(200, 100, 50, 25, "red")
drawEllipse(200, 100, 50, 25, "red", 5)

fillEllipse

Draws a solid, filled-in, ellipse.

name
type
default
description

x*

number

-

the x coordinate of the center of the ellipse

y*

number

-

the y coordinate of the center of the ellipse

width*

number

-

the width of the ellipse

height*

number

-

the height of the ellipse

color

string

'black'

the color to use

Returns

nothing

fillEllipse(200, 100, 50, 25)
fillEllipse(200, 100, 50, 25, "red")

drawRectangle

Draws the outline of a rectangle.

name
type
default
description

x*

number

-

the x coordinate of the top-left corner of the rectangle

y*

number

-

the y coordinate of the top-left corner of the rectangle

width*

number

-

the width of the rectangle

height*

number

-

the height of the rectangle

color

string

'black'

the color to use

thickness

number

1

the thickness of the line

Returns

nothing

drawRectangle(200, 100, 300, 150)
drawRectangle(200, 100, 300, 150, "red")
drawRectangle(200, 100, 300, 150, "red", 10)

fillRectangle

Draws a solid, filled-in, rectangle.

name
type
default
description

x*

number

-

the x coordinate of the top-left corner of the rectangle

y*

number

-

the y coordinate of the top-left corner of the rectangle

width*

number

-

the width of the rectangle

height*

number

-

the height of the rectangle

color

string

'black'

the color to use

Returns

nothing

fillRectangle(200, 100, 300, 150)
fillRectangle(200, 100, 300, 150, "red")

drawPolygon

Draws the outline of a shape with straight sides.

name
type
default
description

pointlist*

array

-

An array of arrays, where each subarray is the [x, y] coordinates of a vertex of the polygon.

color

string

'black'

the color to use

thickness

number

1

the thickness of the line

Returns

nothing

drawPolygon([[100,100], [200,100], [150,150]])
drawPolygon([[100,100], [200,100], [150,150]], "red", 5)

fillPolygon

Draws a solid, filled-in, shape with straight sides.

name
type
default
description

pointlist*

array

-

An array of arrays, where each subarray is the [x, y] coordinates of a vertex of the polygon.

color

string

'black'

the color to use

Returns

nothing

fillPolygon([[100,100],[200,100],[150,150]])
fillPolygon([[100,100],[200,100],[150,150]], "red")

drawString

Draws text on the screen

name
type
default
description

text*

string

-

the text to display

x*

number

-

the x coordinate of the top-left corner of the text

y*

number

-

the y coordinate of the top-left corner of the text

size

number

30

the size of the letters in the text, in pixels

color

string

'black'

the color to use

bold

boolean

false

true for bold, false for regular

italic

boolean

false

true for italic, false for regular

Returns

nothing

drawString("You Win", 20, 550)
drawString(score, 50, 200, 40, "red")

Last updated