NetLogo Bitmap Extension

Using

The bitmap extension is pre-installed in NetLogo. For instructions on using it, or for more information about NetLogo extensions, see the NetLogo User Manual.

What does the Bitmap Extension do?

The Bitmap Extension allows you to manipulate and import images into the drawing and patches. It offers features not provided by the NetLogo core primitives, such as: scaling, manipulation of different color channels, and width and height reporters.

Getting started

To import and manipulate images you will need to include the bitmap extension in your NetLogo model.

The image file formats supported are determined by your Java virtual machine’s imageio library. Typically this is PNG, JPG, GIF, and BMP. PNG is a good, standard choice that is likely to work everywhere.

If the image format supports transparency (alpha), that information will be imported as well.

Primitives

bitmap:average-color bitmap:channel bitmap:copy-to-drawing bitmap:copy-to-pcolors bitmap:difference-rgb bitmap:export bitmap:from-base64 bitmap:to-base64 bitmap:from-view bitmap:to-grayscale bitmap:height bitmap:import bitmap:scaled bitmap:width

bitmap:average-color

bitmap:average-color image

Reports a 3-element list describing the amount of R, G, and B in image, by summing across all pixels, and normalizing each component by the number of pixels in the image, so each component ranges from 0 to 255.

bitmap:channel

bitmap:channel image channel

Extracts either the alpha, red, green, or blue channel from an image. The input channel should be an integer 0-3 indicating the channel to remove (alpha=0, red=1, green=2, blue=3). The resulting image is a grayscale image representing specified channel.

bitmap:copy-to-drawing

bitmap:copy-to-drawing image x y

Imports the given image into the drawing without scaling the image at the given pixel coordinates.

bitmap:copy-to-pcolors

bitmap:copy-to-pcolors image boolean

Imports the given image into the pcolors, scaled to fit the world. The second input indicates whether the colors should be interpreted as NetLogo colors or left as RGB colors. false means RGB colors.

bitmap:difference-rgb

bitmap:difference-rgb image1 image2

Reports an image that is the absolute value of the pixel-wise RGB difference between two images. Note that image1 and image2 MUST be the same width and height as each other, or errors will ensue.

bitmap:export

bitmap:export image filename

Writes image to filename.

bitmap:from-base64

bitmap:from-base64 base64-string

Turns a base64 encoded string into a bitmap image for use by the extension. The Fetch and Export-The extensions would be common sources of these encoded strings.

bitmap:to-base64

bitmap:to-base64 base64-string

Turns a bitmap image into a base64 encoded string with a PNG format.

bitmap:from-view

bitmap:from-view

Reports an image of the current view.

bitmap:to-grayscale

bitmap:to-grayscale image

Converts the given image to grayscale.

bitmap:height

bitmap:height image

Reports the height of given image

bitmap:import

bitmap:import filename

Reports a LogoBitmap containing the image at filename.

bitmap:scaled

bitmap:scaled image width height

Reports a new image that is image scaled to the given width and height

bitmap:width

bitmap:width image

Reports the width of the given image