Taking Advantage Of Virtual Screens

Psychic Symphony

You have two virtual screens and a Pentium? Let's use them properly then... Instead of doing an effect and then plainly move it to the screen, why not wrap it up a little?

BTW - I'm writing this down thinking you are using a grayscaled 256 palette! Since I don't know much about hi-colour I won't pretend to write that it is easy to implement... Ask someone who knows! It might, it might not!

Easier is to just grab a surrounding pixel matrix!

From 1 to x-1
From 1 to y-1

You grab the matrix:

        | 1,1 2,1 3,1 |
        | 1,2 2,2 3,2 |
        | 1,3 2,3 3,3 |

(2,2) being your current x,y position!

Notice I wrote from 1 to x-1 and not 0 to x so that we don't grab external values. We'll think more about that later...

So, you have a matrix of values... Whee! So what?

Now you need to retrieve an x,y for your position! This is where you use the virtual screen... Grab values from virt1 and retrieve to virt2!

But what are you retrieving?

Well... you can have:

 Plain blur:
  value1= (1,1) + (1,2) + (1,3) + (2,1) + (2,2) + (2,3) + (3,1) + (3,2) + (3,3)
  value2= value1 / 9
  Note: Final x,y value is value2.

 Faster blur:
  value1= (1,2) + (2,1) + (3,2) + (2,3)
  value2= value1 / 4
  value3= value2 + (2,2)
  value4= value3 / 2
  Note: Final x,y value is value4.

 Limited random:
  value1= (1,1)
  value2= (1,2)
  ...
  value9= (3,3)
  value10= value<random(1-9)>
  Note: Final x,y value is value10.

 Higher:
  value1= (1,1)
  value2= (1,2)
  ...
  value9= (3,3)
  for a=2 to 9 if value<a> > value10 then value10=value<a>
  Note: Final x,y value is value10. This will retrieve the highest value!

 Higher-1:
  Same as before!
  value11=0
  if value10>0 then value11=value10-1
  Note:  Final x,y value is value11. This will retrieve highest value -1! Might
  seem stupid at start, but it will come out handy later on!

OK! these are enough for now... So what you are doing right now is to go through every pixel on virt1, get the surrounding ones and based on those values and the effect you use, retrieve the x,y for virt2!

Now, before you send this virt2 to screen think a little, what if we re-applied the effect back to virt1?

This is how we take advantage... Apply your effect only on the other direction this time, from virt2 to virt1! Now you can dump it to the screen!

Let's not forget the original picture, normally some letters on a black background, so if you apply, for instance, blur to virt2 and blur again to virt1 you'll pretty soon run out of picture! What you need is to re-impose the letters on the pic at this stage over the effect you have created, let's call it our source!

So the whole effect is based on the source's location and the two effects you apply back and forth! What you need to do know is to mess with:

1) Source's movement
Sinus movements look smoother!

2) Source's ratio of appearance!
You can put re-impose source on virt1, virt2, alternatly, randomly, on different schemes, synced with something...

3) Virt to screen
Like with source re-impose, you can choose when do you want to update the screen!

4) Effects blending
This is where higher-1 looks good, try higher-1 to virt1 and blur-fast to virt2 and check out how smooth and cool it looks... Other things can be used, but higher-1 really gives an extra edge because it helps spreading the colour!

That is not all, there is a lot of optimization to do on the get matrix section, getting 9*64000*2 pixels per frame is slow enough! We don't want to waste time with unnecesary calculations! I wrote 64000 because that's 320*200! Bigger res, slower frame-update! That's the main advantage of using blur-fast in here, you only need to grab 5 pixels, not whole 9! Try using the other fx with only 5 pixels as well, see where you can cut some slack. Beside this you can check if colors are similar before making divisions on blurs! If you're grabbing 9 color(0) you don't have to add all and divide by 9 to know the result will be 0 now do you?

That is it. Blur-fast was applied after reading an article from Dake of Calodox, you can find it in DefCon#2 and Hugi#13 as well since it belongs to [TEN]!

The only problem with this is that it is slow if not remotly optimized and every single person who doesn't have a fast Pentium will say it looks too slow for a 320*200*256 effect! They don't really see how many calculations they are seeing per frame! And since everyone loves hi-res and hi-colour nowdays the effect will just be lying in my HD! So I thought I would do a favour to these damn diskmags who keep asking people for articles on coding!

Anyone who knows Assembly should make it work fine and fast though... And anyone who knows hi-coulor stuff should make use it in some way... I'm too stupid to find a proper use! Have fun...

If you want a half-optimized pascal version (got tired of optimization!) just mail asking 4 it!

- Psychic Symphony