I need a suggestion about displaying images.

By Evhor

Resident (54)

Evhor さんの画像

02-06-2015, 11:40

Greetings, everyone!
I would like to copy an image on the screen with an effect which is not the usual pop. I've seen images copied pixel by pixel (or block by block) with a pseudo-random path, as if the image is snowing on the screen. Could someone please give me an advice about the proper algorithm to generate such path?

ログイン/登録して投稿

By ARTRAG

Enlighted (6976)

ARTRAG さんの画像

02-06-2015, 12:46

How large are the pictures you need to show ?

By Poltergeist

Champion (280)

Poltergeist さんの画像

02-06-2015, 12:50

I used such an effect on Quattro... First you need to determine how big the blocks will be that will pop up. Let's say 16x16 pixels. On screen5, you would need 16 blocks in the x-asis, and on 14 the Y axis. That would make 224 blocks. Reserve 224 bytes somewhere (it could be done in 224 bits, but it's the idea that counts).

Pseudo basic:

10 for cn=1 to 224
20 bl=rnd(224)
30 if byte(bl)=0 then (copy block bl from page 1 to page 0) else goto 20
40 byte(bl)=cn
50 next cn

this would ultimately fill all the blocks, but it might get a bit slower, as in the end, more and more blocks are filled already. Running this ones and storing the values gives a path which is always the same.

This could be done way more efficient, but you probably get the idea...

By Marq

Champion (387)

Marq さんの画像

02-06-2015, 13:02

With blocks make an array with numbers representing the blocks {0,1,2,3,4,...}, and then "shake" it: swap each number with another at a random position. This way you'll have a nicely random order and each block there only once.

By ARTRAG

Enlighted (6976)

ARTRAG さんの画像

02-06-2015, 13:48

Random reshuffle is the way

By Evhor

Resident (54)

Evhor さんの画像

02-06-2015, 16:22

At first, thank you very much for your feed-back.

@ARTRAG
Hi, there! How things are going?
Actually, I should have been more specific.
Images are made by 8x8 blocks.
Width is in the range from 8 (1 block) to 256 (32 blocks).
Height is in the range from 8 (1 block) to 128 (16 blocks).
And... yes, it serves for my visual novel project.

What I am really looking for is a formula to calculate the next block without stumbling on the already copied ones. I was working on this solution but I must tell that it doesn't look very random and I haven't understood yet under which conditions it covers the whole image.
In the end, I guess the random reshuffle is the best solution in visual terms, despite it takes memory for the array and time for the shuffling. Hehe... we have a proverb which sounds like:"If you want to look beautiful you must be ready to suffer a little" Wink

By ARTRAG

Enlighted (6976)

ARTRAG さんの画像

02-06-2015, 16:37

Use an array of 256 elements,filled with 0-255,randomly displace the elements by swapping them (each item is swapped with the one in a randomly choosen position).
Reuse the array many times in the plotting of the screen as offset from the base position.
generating the array is a two pass operation, it should quite fast for a 256 array
reusing it many times is a way to save ram and the effect should be decent as the animation repeats each 32 tiles
(You basically plot a line of tiles at time)