Pardon the mess, Play My Code is in beta!

READY TO PLAY?
CLICK TO LOG IN!

sign up - lost password

fillPolygon

This allows you to fill custom shapes, on the screen. This includes triangles, quadrilaterals, or something much more complex.

Depending on which function your using, the points can be provided in 1 or 2 arrays, and can be translated along the x and y axis.

fillPolygon( points )

Draws a filled polygon using the points given. The 'points' array is presumed to be an array of numbers, in the order of x, y, x, y, x, y, and so on.

// draws a kite shaped object
aKite = [ 150, 100, 200, 150, 150, 300, 100, 150 ]
fillPolygon( aKite )

fillPolygon( points, x, y )

Fills a polygon, in the same way as the previous 'fillPolygon' function, but when drawn it is translated by the x and y values given.

// draws a kite shaped object, translated
aKite = [ 150, 100, 200, 150, 150, 300, 100, 150 ]
fillPolygon( aKite, 100, 0 )

fillPolygon( xs, ys )

This version of 'fillPolygon' takes separate arrays for the x and y values.

aKiteXs = [ 350, 400, 350, 300 ]
aKiteYs = [ 100, 150, 300, 150 ]
fillPolygon( aKiteXs, aKiteYs )

fillPolygon( xs, ys, x, y )

Takes separate arrays for the x and y points of the polygon, and allows you to translate it by the 'x' and 'y' values given.

aKiteXs = [ 350, 400, 350, 300 ]
aKiteYs = [ 100, 150, 300, 150 ]
fillPolygon( aKiteXs, aKiteYs, 100, 0 )
/**
 * All four kites together.
 */

aKite = [ 150, 100, 200, 150, 150, 300, 100, 150 ]

aKiteXs = [ 350, 400, 350, 300 ]
aKiteYs = [ 100, 150, 300, 150 ]

onEachFrame() do
    fill( :blue )
    setColor( :white )
    
    fillPolygon( aKite )
    fillPolygon( aKite, 100, 0 )
    
    fillPolygon( aKiteXs, aKiteYs )
    fillPolygon( aKiteXs, aKiteYs, 100, 0 )
end

See Also