Thursday, 7 December 2017

JavaScript XBM drawing capability

The foundation of our XBM drawing capability is the drawPoint() method, xbmDrawPoint().As all of our XBM drawing methods, the drawPoint() method doesn't actually draw anything on the screen.
Instead, it updates the internal state of the xbmImage object to indicate that the specified point needs to be drawn.

Our XBM images is made up of two types of objects: the xbmRow object, which contains an array of 16-bit numbers, and the xbmImage object, which contains an array of xbmRow objects
These objects both contain additional information used in manipulating the image and in translating it to ASCII text for display.

The xbmImage() constructor takes the width and height of the image, in pixels, as parameters. An optional initial value can also be specified-if supplied; this will create a pattern of vertical lines in the image. Otherwise, a zero is assumed, which results in a blank image.

The xbmImage() constructor calls the xbmRow() constructor to create each row in the image. xbmRow() should be considered an internal function. You don't need to call it directly.
Both xbmImage and xbmRow have toString() methods: xbmImageString() and xbmRowString(), respectively. These create the ASCII representation of the XBM image when it's time to display it.

A third method, xbmPartitionString(), optimizes the string-building process, which would otherwise consume an excessive amount of memory.

The best way to animate images using JavaScript is not to. Netscape 2.0 supports GIF89a multipart images, which contain built-in timing and looping instructions. These load faster and run more smoothly than animation created using JavaScript and can be placed anywhere on the page.

A number of inexpensive shareware utilities are available for creating GIF animation, the best-known of which is probably GIF Construction Set by Alchemy Mindworks. While GIF89a images are currently supported only by Netscape, it's pretty safe to assume that when other browsers support JavaScript, they'll also support GIF animation.