notthecheatr Blixer Object

Blixer is perhaps the most versatile of all the effects I have created so far.  It does a number of
different things, depending on what you tell it to do.  Blixer stands for "BLock mIXER" and its name is
pretty self-explanatory.  It takes a single image, displays it on the screen, then grabs random blocks from
that image and places them in a random location near the location they originated from.  This is very simple, but
it gets a lot more complicated.  You may draw things with alpha blending.  You may specify the size of blocks you
wish to move around.  You may choose to draw the random blocks onto the original image as well as onto the
target, or only onto the target.  All these options mean there are quite a number of special effects that can
be achieved just using this one object.

----------Usage----------
Like all the other objects, you must include it in your program using the following code:

    #Include Once "blixer.bas"
    Using ntc.specialfx

After that, you can create a blixer object like this:

    Dim myBlixer As blixer

Now like all my special effects objects, you must specify the image you wish to blix;  this can be any image
you've already loaded from a file, for example, or an image you've created.  It must be an image buffer; though
it's probably possible to use the screen, I haven't tested it and I don't recommend you do.  Don't start the
blixing process until you've entered a graphics screen mode, as blixer needs to create an image buffer and
you can't do that outside of a graphics screen mode.  This is logical, since you'll probably need to create
a graphics buffer to pass to the blixer object anyways.

Once you have an image, you can pass it to the blixer:

    myBlixer.blix(myImage)

Perhaps surprisingly, you only need one parameter to use the blixer, and that is the image to blix.  All
other parameters are optional.  Without specifying any parameters, the effects will be minimal.  At least
you should specify values for the next two - you might try

    myBlixer.blix(myImage, 5, 5)

which will give you a frost-like effect.


After you start the blix, you won't actually see anything on the screen unless you use the update() method.
Since blixer is (like all my special effects) designed to be used inside of a loop (so it can, for example,
be used within a game loop), you need to start a loop, then make calls to the update() method.  Many of my
effects will tell you when they're finished running;  blixer doesn't do that, it can run forever if you like.
You can do it based on how many ticks have gone by, or you can do it based on whether the user presses a key, or
anything else.  Here's an example loop:

    Do
      myBlixer.update()
    Loop Until MultiKey(FB.SC_ESCAPE)

This simply loops until the user presses ESCAPE.


That's really all there is to it, if you want to quit early or if you want to be able to destroy the internal
image buffer to conserve memory, you can use

    myBlixer.finish()

but otherwise everything is taken care of when the program ends or the object is destroyed.


Now, what about all those parameters I talked about earlier?  Well, they all come under the blix() method.
They're all optional, but obviously you'll want to play with them to see what kinds of effects you can achieve.
I'll list them in order below, with their name, type, default value, and description.

randomnessX As Single = 1 
randomnessY As Single = 1 - These simply allow you to specify the maximum distance a block may be moved from the
  part of the image it was originally taken from.  For example, the default randomnessX value of 1 means that when
  a block is taken from a random part of the picture, it may be moved up to 1 pixel in either direction on the
  x-axis.  The same is true of randomnessY and the y-axis.  They are specified separately so if you want the
  effect to be mostly vertical or mostly horizontal, it can be.  The higher you set this, the stronger the effect.

blockSize As uInteger = 1 - This is the size of blocks taken.  The default is 1, meaning the blocks are a single
  pixel, but it may be set to higher values, moving larger blocks at a time.  This is one of the settings that
  can make the effect really interesting, if you use it right.

blocksPerTick As uInteger = 1 - This simply specifies how many blocks are to be moved every time you call the
  update() method.  It doesn't have a major effect on anything, but it can affect how fast the image changes.

imageMode As Byte = 0 - This is used to set the drawing mode of your image.  If you just want it to be drawn using
  the PSet mode, you keep it at its default value of 0.  If you set it to 1, it will draw using Trans;  this could
  be useful if you have transparent patches on your image (transparent patches being patches of the colour
  &hff00ff in 32-bit mode or 0 in indexed mode).  2 is Alpha, if you have an alpha channel.  3 is where it gets
  interesting.  3 lets you specify an alpha value to draw the blocks at, so if the blocks will not completely
  overwrite the blocks beneath them.  The effect can be more of a blurring effect depending on how you do it.
  Many interesting effects can be achieved even without this, but you can do some interesting things with it.
  Because uniform alpha blending automatically removes transparent patches (&hff00ff or 0), if your image is not
  intended to use transparency removal then you should use my safeAlpha sub which replaces all occurences of
  &hff00ff with &hff00fe, which looks practically the same but will not be treated as transparent.

blixMode As uInteger = 0 - This is the mode of blixing.  Normally it's 0, meaning the blocks moved are only
  moved onto the target (the screen, by default) - but a nonzero value means the blocks are also placed in the
  same position on the original image as well.  This will change your original image, so if you need it to stay
  intact, be sure to make a copy in memory!  The cool thing is that it makes the effect more smooth, kind of like
  a painting instead of jiggling blocks, so it can be used for some cool effects.

target As FB.Image Ptr = 0 - This is the target you wish to draw to.  Normally it's 0, meaning things are drawn
  to the screen, but it can be changed.

blixAlpha As uByte = 255 - This is the alpha value the blocks are to be drawn with, but it has no effect unless
  imageMode 3 is used (see imageMode, above).  A low setting means the blocks drawn don't actually change the
  image a whole lot;  if you make really big blocks and small movement settings, it will give you kind of a
  wavy blur effect.


You can play around with those a bit;  you'll find a wide variety of different effects that do various interesting
things.  Here are some examples I've found:


  myBlixer.blix(bgImg, 5, 5, 10, 10000, 0, 1, 0, 255)
Gives a squiggly painting effect


  myBlixer.blix(bgImg, 1, 1, 100, 10000, 3, 1, 0, 32)
At first gradual, this gives a very marked effect after a few seconds.

  myBlixer.blix(bgImg, 10, 10, 100, 10000, 3, 0, 0, 32)
This is a nice jiggly effect.

  myBlixer.blix(bgImg, 2, 2, 100, 10000, 3, 1, 0, 255)
This is a particularly interesting effect, it essentially wipes everything around, so it looks like a wet
painting being jiggled around a lot until you can hardly recognize the image at all.  Playing with the block
size and randomness values produce a lot of interesting variations.

A lot of different effects are achievable with this, a bit of experimentation will surely uncover more.