Class Canvas

Contains drawing operations.

Methods


clear [color <color c = Color.black>]

Clears the canvas object with a color.

Parameters

Example

main
  system.run application new MyApplication
                
class MyApplication extends Application
  draw to <canvas g>
    // Clear object to white
    g.clear color Color.white
                

draw bitmap <bitmap bmp> to <position bitmapPos> [alpha <int a = 255>]

Draws a bitmap. The optional alpha value specifies the opaqueness of the drawn bitmap.

Parameters

Example

main
  system.run application new MyApplication
                
class MyApplication extends Application
  draw to <canvas g>
    Bitmap bmp = new Bitmap from file "example.png"
    // Draw bitmap to upper left corner
    g.draw bitmap bmp to 0,0
                

draw bitmap <bitmap bmp> to <rectangle targetRect> [offset <position bitmapOffset = 0, 0>] [alpha <int a = 255>]

Fills a rectangle with bitmap. The bitmap is tiled if it does not cover the whole targetRect area.

Parameters

Example

main
  system.run application new MyApplication
                
class MyApplication extends Application
  draw to <canvas g>
    Bitmap bmp = new Bitmap from file "example.png"
    // Draw bitmap to rectangle starting at upper left corner with size 100x100.
    g.draw bitmap bmp to 0, 0 size 100, 100
                

draw bitmap <bitmap bmp> to <position bitmapPos> source <rectangle sourceRectangle>[alpha <int a = 255>]

Draws a part of bitmap. The sourceRect specifies the area to draw. This area will be clipped to the bmp's boundaries.

Parameters

Example

main
  system.run application new MyApplication
                
class MyApplication extends Application
  draw to <canvas g>
    Bitmap bmp = new Bitmap from file "example.png"
    // Draw 50x50 area of bitmap to upper left corner.
    g.draw bitmap bmp to 0, 0 source 0, 0 size 50, 50
                

draw string <string str> to <position textPosition> [color <color textColor = color.white>] [font <font f = system.get default font>]

Draws a string.

Parameters

Example

main
  system.run application new MyApplication
                
class MyApplication extends Application
  draw to <canvas g>
    // Draw string "Test data" with default font to upper left corner
    g.draw string "Test data" to 0,0
                

draw string <string str> range <range strRange> to <position textPosition> [color <color textColor = color.white>] [font <font f = system.get default font>]

Draws a string.

Parameters

Example

main
  system.run application new MyApplication
                
class MyApplication extends Application
  draw to <canvas g>
    Font f = system.load bitmap font from file "bitmapFont.png"
    // Draw string "Test" to upper left corner with blue color and loaded font.
    g.draw string "Test data" range 0 size 4 to 0,0 color Color.blue font f
                

draw rectangle <rectangle rect> [color <color rectangleColor = Color.white>]

Draws a filled rectangle.

Parameters

Example

main
  system.run application new MyApplication
                
class MyApplication extends Application
  draw to <canvas g>
    // Draw green rectangle of size 50x50 to position 100,100
    g.draw rectangle 100,100 size 50,50 color Color.green
                

draw line from <position fromPos> to <position toPos> [color <color lineColor = Color.white>]

Draws a line from fromPos to toPos.

Parameters

Example

main
  system.run application new MyApplication
                
class MyApplication extends Application
  draw to <canvas g>
    Size screenSize = screen.get size
    // Draw orange line from top left corner to bottom right corner.
    g.draw line from 0,0 to screenSize.get width, screenSize.get height color Color.Orange