Sunday, 22 March 2009

Chunk 79 - Introduction

In the preceding chapters, we have seen how the pixels array can be used to apply different effects, to the screen display. In order to perform these pixel operations, it is usually necessary to set up some kind of loop to work on each separate pixel. In this chapter we look at the filter method, which allows us to carry out various effects, on the contents of the display screen. The effects affect every pixel and cannot be applied to specific areas of the screen, although theoretically, you could achieve this using the translate function.

The filter method is very simple to use and accepts eight different constant parameters, which apply different filters to the screen content. The parameters accepted by the filter method are: INVERT, GRAY, THRESHOLD, ERODE, DILATE, OPAQUE, BLUR and POSTERIZE. The signature of the filter method is filter(MODE), where MODE is one of the parameters listed above. Some modes can also accept an integer or float, that specifies the intensity required, if no second parameter is provided, a default value is used, which is usually mid range.

Before discussing each filter in depth we will look at an image transformed by each filter mode, so we can compare the different effects.

As can be seen from the images, using the filter method and its modes, can spectacularly transform an image. Some of these effects had the filter applied several times, to emphasize the effects produced. The astute observer may have noticed, that the opaque image is no different from the original image. This is because our example image has no transparent areas. Some very dramatic animations can be created, by varying the intensity parameter of a filter and displaying each effect in a loop. We will now discuss the modes in depth. Most modes will have a small animation to illustrate their functionality.

No comments:

Post a Comment