tutorial FEBRUARY 6, 2001 • page 1, 2, 3, 4, Home

How To Write Your Own Photoshop Filters
[Page 3 of 4]

X and Y meet x and y
To this point, we've just been looking at how the sliders control channels as simple numeric values. Nothing too troublesome. But all we've been able to do is to create solid colors. Hardly worth the effort of writing a filter, right?
That's because we haven't told Filter Factory to deal with any specific pixels. Our changes have simply been made to the total image, destroying the original and replacing it with a solid color.

Now we're going to tell Filter Factory what we really want it to do: generate effects.

This is where variables come into play. Just like junior high algebra. Well, not "just like," but close enough. Today we're not going to explore all of the variables. We'll save some for later. Here's what we're working with:

  • X, which represents the width of your image;
  • Y, which represents the height of your image;
  • x (lowercase), which represents the horizontal position of any given pixel;
  • y (lowercase), which represents the vertical position of any given pixel;
  • ctl(0) through ctl(7), which uses the slider value of the eight controls to generate a number;
  • r, g, b, a (all lowercase), which allow you to substitute the value of one channel for the value of another. In other words, if you want your red channel always to behave just like your blue channel, you can just type "b" in the R entry field. This basically tells Filter Factory to copy the formula from the B entry field to the R entry field (although you will not see the formula in the R entry field). You can also do things like b-ctl(0), which will tell the field to generate the same value as the blue channel minus whatever the number is in Control 0.

Now you just put it all together with four operators and two functions. Settle down, Avery; it's not what it seems. Operators are simply addition, subtraction, multiplication and division, represented at +, -, * and /. You don't really have to worry about what functions are, since we're only using two: src() and rnd(). This "src()" is simply a way of telling Filter Factory that you want to manipulate pixels from your source image. So, if I write src(x+1,y+1,0), I'm telling Filter Factory to move the horizontal and vertical positions of my color (in this case red, represented by the 0) one pixel up and over. The "0" at the end there simply represents the channel being affected. I know this sounds a little ridiculous, but you just have to remember that red is 0, green is 1, blue is 2 and alpha is 3. That's just the way it is. It's one of those things that gets Avery all mad, but he's going to have to deal with it because, if you don't enter a 0, 1, 2 or 3, you'll get an error.

The rnd() function simply generates a random number between two numbers. So, for example, rnd(1,35) will generate a random number between 1 and 35. It's handy sometimes, and I use it in the downloadable examples I've supplied, so I though I'd better bring it up here.

So let's bring in a slider or two. In the R entry field, enter: src(x+ctl(0),y+ctl(1),0). Now play with the first and second slider. What's happening here is that you're telling Filter Factory to find all of the red information from any given pixel and shift its position a number of pixels horizontally (x) and vertically (y) equal to the values of Control 0 and Control 1 (otherwise known as the first and second slider). You could also type src(x-ctl(0),y-ctl(1),0), which will make the red values move the other way when you move the slider because, instead of adding the value of the slider, it's subtracting it.

If this is all you want to do with all of your channels, simply enter the following into each:

  • R: src(x+ctl(0),y+ctl(1),0)
  • G: src(x+ctl(2),y+ctl(3),1)
  • B: src(x+ctl(4),y+ctl(5),2)
  • A: src(x+ctl(6),y+ctl(7),3)

In this last example, the alpha channel will not be affected visibly unless your image contains transparent areas.

Go to Page 1, 2, 3, 4, Home

Post a comment or question in the Digital Media Designer User Forum!

tutorials 2001

[an error occurred while processing this directive]