TopExplaining Drawable Images

Drawable Images

Demo. Drag a Snowman

In the above demo program, we drag a picture of a snowman around the screen. The picture comes from a "gif" file named snowman.gif.

The first line of the begin method of the Snow class shows how to do this when given a "png" file (a particular format for holding images on-line):

   def snowman: Graphic2D =
        drawableImage.at(10 @ 10)size(124, 144)
            url("http://www.cs.pomona.edu/classes/cs051G/Images/snowman.png") on(canvas)

Downloading an image from the web can often be slow, so we usually will want to create an image from the "png" file at the beginning of a program and save it until we need it. If you download "png" files in the middle of your program, you may cause a long delay while the computer brings it in from across the internet.

The class drawableImage from our objectdraw library will allow you to treat an image roughly as you would a rectangle. In fact, imagine a drawableImage to be a rectangle with a picture embedded in it. You can do everything you would with a rectangle, except that there's a neat picture on top.

If you want to manipulate that drawableImage in interesting ways, you'll need to associate a name with it as usual. You can then invoke all the standard rectangle methods on the VisibleImage. For example:

    snowman.width := 100
    snowMan.height :=100

TopExplaining Drawable Images