What if you need to use more complex graphics than you can easily build using Graphics class methods? In this case, you can create or find on the Internet an image file, load it into an object of Image class and draw using method Graphics.drawImage(). Here is an example:

package demos
import com.anysolo.toyGraphics.*

fun main() {
    val wnd = Window(300, 200)
    val gc = Graphics(wnd)

    val image = Image("graphicsFiles/brick-wall.jpg")
    gc.drawImage(50, 35, image)

Image class Image supports PNG, JPG and GIF files.

You can draw an image rotated to any degree. Be default it will be rotated around its top left corner, but you can specify the point you want to rotate your image around. Below you can see the example wich rotates UFO image around its center.

package com.anysolo.toyGraphics.samples

import com.anysolo.toyGraphics.*

fun main() {
    val wnd = Window(300, 300, background = Pal16.black, buffered = true)
    val image = Image("graphicsFiles/ufo-small.png")

    val x = wnd.width/2 - image.width/2
    val y = wnd.height/2 - image.height/2

    val maxAngle = Math.PI*2
    var angle = 0.0

    while(true) {
        Graphics(wnd).use {g ->

            val anchorx = x + image.width/2
            val anchory = y + image.height/2

            g.drawImage(x, y, image, angle, anchorx, anchory)

            angle += maxAngle/360
            if(angle > maxAngle)
                angle = 0.0