RIPPLES
(C) Reaper / ZX-MANIACS
In this article I decided to describe
effect, known in other
platforms, like rain on the water. He
represents a divergent concentric circles
(As a consequence, the water droplets from
rain). This effect is particularly
like water, if a community
have any picture.
However, this modification
effect on the Spectrum do
nice quite difficult (although
For example, in the demo this Emergency
the effect is and he looks very
not bad). Be that as it may, I will describe the usual effect,
no background image. In the end, I think I'll say a couple of
words about the algorithm works with a background image, but
the example will not lead.
Bitmapovsky effect, so
make it possible to attribute or
a chunk.
So, to create the effect you
need two buffers are equal
the size of the screen. For example, the example uses chunks.
They are displayed on the 2 / 3 screen so that the size of both
buffers should be 64 * 32. But there is a
one subtlety. It is advisable to leave untouched (permanently
equal to zero) strip thickness of 1 chunk along the perimeter
of the buffer. Therefore, in my example uses a buffer size of
66 * 34, but displayed only the inner portion of 64 * 32.
You can leave the buffer size
64 * 32, but then the process
should only be the internal area of 62 * 30 (this,
incidentally, gives increase in the rate of the decrease in
cultivated area and because of the simplicity of conversion in
Format 2 chunk in bytes (or acceleration of output chunks, if
you use the procedure output
chunks in the format of a chunk in
B)).
One of the buffers is current (ie, it is constructed
image), and the second - the previous one (that was on the
screen after the previous pass effect). The main effect of
meaning lies in the following sequence of actions:
1) Put up signs in
upper-left cell of the current and
previous buffers (preferably in
cell at 1 bar below and at 1
column to the right of the top-left, etc.
since this will enable not affect the extreme row and column);
2) Take the values of the four cells around the current in
the 'previous' buffer and add them;
3) The resulting number is divided by 2
and subtracted from the value of the current cell in the
'current' buffer;
4) If the resulting value
less than zero, equating it to
zero. Chop him also to
maximum (in my example, the maximum value that
perceive chunks - 31, so
the resulting number dub
simply AND 31);
5) So now what we got, we put into the current cell in
'Current' buffer;
6) Physically move pointers
these cells in both buffers
and completes the cycle (first by
columns, and then by rows);
7) Swap the current and
the previous buffer. More precisely, we simply swap the
pointers, and now the current buffer will be the previous and
vice versa.
That is, in general, and the entire inner loop effect it. Now
you can get stuck on step 1. If the
'Previous' buffer supply
point, then it gets going in circles.
For clarity, we present an algorithm in a sort of pseudocode
basically looks like a Spekovsky BASIC.
Assume that we have
two buffers: COLD (M, N) and
NEW (M, N). So it will look like
procedure 'run circles' in them
(To simplify the verification is omitted
values at the output of range).
DO
X = INT (RND * (N - 1)) + 1
Y = INT (RND * (M - 1)) + 1
OLD (Y, X) = 15
FOR I = 2 TO M - 1
FOR J = 2 TO N - 1
A = OLD (I-1, J) + OLD (I +1, J) +
+ OLD (I, J-1) + OLD (I, J +1)
A = A / 2 - NEW (I, J)
NEW (I, J) = A
NEXT J, I
NEW (M, N) -> SCREEN
SWAP OLD (M, N), NEW (M, N)
LOOP WHILE NOT KEYPRESSED
Here NEW (M, N) -> SCREEN - conclusion
on the screen (in this case refers to chunks, taking
values from 0 to 15. It
so the 'previous' buffer
as a 'source' circles put the point with a value of 15). In
this example, a new source community put into the buffer before
each inner loops. This gives a very large number of laps
on the screen and turns melteshenie ... but it's still pretty
entertaining.
You might ask,
why source code works with cell values equal to 0 .. 31,
if chunks only accept
the values 0 .. 15 and have further to convert. All
The fact that the size of the circles
depends on the chislaistochnika. If you put the source number
15, then circles are obtained small and ugly. Shown to be 63
(Because, IMHO, made a demo
BlAME), but most of all I
like the version with source
equal to 31.
That's, like, that's all. Finally,
as promised, will discuss how to start up community over the
picture. For this, you naturally need to buffer the picture.
For simplicity, we assume that it equals the size of 'current'
and 'Previous' buffer (to
well, that's usually the case).
The algorithm is as follows:
1) doing all the usual
steps to create a community, but
do not output 'current' buffer on
screen;
2) Now we are considered 'current' buffer and buffer image.
For each element, the following buferakartinki
steps:
3) Take the value from the corresponding cell of 'current'
buffer and subtracted from it the value of the cell to the
right of this (Still in the 'current'
buffer). Obtained by the displacement of
X;
4) now takes the value
corresponding point of the 'current' buffer, and subtracted a
point on the line below. Obtained by the displacement of Y;
5) Both the bias can be divided into any number. On the PC in
256tsvetnom effect is best to divide by 8. At Speke in chunks
probably fit the division into 4 though it is selected an
experienced infections;
6) Take a point in buferekartinke, located on the current
distance calculated displacements, and put the current position.
7) And so the cycle at all points.
It bears mention that in
calculating the position of the new point, which should be put
in place the current, you should check coordinates on moving
beyond buffer.
And now the algorithm in pseudocode. In this algorithm, for
simplification, not above
checking out the coordinates for
outside the buffer. So, NEW (M, N) -
'Current' buffer, SCR (M, N) - buffer-image, OUT (M, N) - buffer
which will be displayed on the screen.
FOR I = 2 TO M - 1
FOR J = 2 TO N - 1
XS = NEW (I, J) - NEW (I, J + 1)
YS = NEW (I, J) - NEW (I + 1, J)
XS = XS / 4
YS = YS / 4
X = J + XS
Y = I + YS
OUT (I, J) = SCR (Y, X)
NEXT J, I
OUT (M, N) -> SCREEN
It is not hard to see the calculation
displacements are very smacks of calculation of the
pseudo-normal at bumpmapping'e. So, here
we are in a sense, doing
bampopodobnoe light pictures.
Algorithm for the full effect circles
over the picture in general terms
looks like this:
1) puts an end to 'previous' buffer;
2) On the basis of 'previous' and
'Current' image buffers is calculated in the 'current' buffer;
3) On the basis of 'current' buffer
and buffer-image is calculated
image in the output buffer;
4) The output buffer is displayed on the
screen;
5) And again at point 1 (or claim 2,
if you do not need to put a new source community).
Now it all. I hope you
anything learned from my
paranoid delusions. In the Appendix you can find the source
this effect on ACME. It
You can control the cursor
6/7/8/9 keys and let community 0 key. In the source file is
explanations so that you do
have a chance to sort out in practice, if you're still not all
understood.
PS: The above source is very slow. How to make
faster, and it can be done
you have to think for yourself!