News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Falling snow effect

Started by hfheatherfox07, August 03, 2011, 11:19:53 PM

Previous topic - Next topic

hfheatherfox07

Hi , I came across this video on youtube http://www.youtube.com/watch?v=75AHKaSPUD8

About 17 seconds in there a Falling snow effect....

Does anybody know how that is achieved?
Or has anybody sen this before? it looks so cool

zekyr

im still learning a lot about assembly and i dont know much! so i dont know if i should be the one to contribute but i'd like to try! :)

the snowflakes just look like static images that are just moving down the screen, the side to side stuff could be done by some kind of periodic function like sine, which in the context we're using it is just a function that would return between -1 and 1 floating point, so you give it an angle increasing linearly and it kinda makes stuff move smoothly back and forth between those two values.

in c you'd do like
counter += (PI / ITERATIONS_PER_WIDTH);   //by PI we've moved an entire width, so we divide that by how many times we iterate to move a width
snow_flake.x = sin(counter)*(WIDTH_OF_MOVEMENT)/2   //moves between -1 and 1, so we have to account for that by dividing by 2

in asm you'd have to use the fpu to get something cool like that and i dont know much about that! :)

the absolute value of a signed interpretation of any memory size should give you a periodic function that looks like a triangle if you get the abs

say we have a byte, the values count like this:
unsigned : 1,2,3,...,125,126,127,128,129,130
signed :    1,2,3,....,125,126,127,-128,-127,-126 : i.e. 126,127,128,127,126, periodic and linearly smooth!

dont think that'll help though. i dont know how to get the absolute value in asm and looking at the opcode list in masm32's help files it might be better just using cmp, je, inc, and dec rather than trying to be clever :(

you could use BitBlt to draw the snowflake

BitBlt will transfer a DC to the DC of a window so you could put a snowflake in a DC then tell it to bitblt to the window multiple times, from there it'd just be updating the positions and bitblting all the snowflakes.

theres a recent post that qWord responded to on how to use bitblt and how to create a Memory DC and all kinds of cool graphic jazz:
http://www.masm32.com/board/index.php?topic=17109.0

ill post the crappy code i wrote to play with graphics as well!

ToutEnMasm


in iczelion site , there is a very good similar sample who made a water effect on the screen.
Modify it a little and you will have a snow effect

hfheatherfox07

Thank you all for the responses .... I started this post, after I emailed the author of that video for the falling snow effect and got no response....

It turned out that the author was on a vacation  , and got back to me today .....

the author was nice enough to email me this effect here it is (the way I got it, sorry about the "about content") :dazzled:








dedndave

i noticed he has a blog, too
somewhere in there, you can probably find the "28 ASM Effects" article

http://xylibox.blogspot.com/

might want to be careful with his downloads, though   :P

Magnum

This is way cooler at 335 bytes.
Have a great day,
                         Andy

hfheatherfox07

Quote from: dedndave on August 04, 2011, 08:44:40 PM
i noticed he has a blog, too
somewhere in there, you can probably find the "28 ASM Effects" article

http://xylibox.blogspot.com/

might want to be careful with his downloads, though   :P

LOL No Thanks .... that will harm my computer most likely .....

the rest of the graphical effects minus one of them are from "THE CYBERDOOM SYSTEMS"   :red....I don't want to post the link due to the content but if you Google it .... at least 26 of them

hfheatherfox07

Quote from: Magnum on August 04, 2011, 08:59:19 PM
This is way cooler at 335 bytes.

LOL a com file....

that would be cooler if it was a win32 with source  :8)

Magnum

I looked into it, but it's a very complicated using opengl.

It's a steep learning curve.

Have a great day,
                         Andy

zekyr

yay i think i got some of it right! i see sin and bitblt and a snowdc in here. thank you so much for posting this! :) i always wondered how people did those cool looking window frames. and it has threads in here! i have much to learn :)

bomz

translate most remarks

qWord

hi,
in the attachment an example using GDI+.

qWord

EDIT: there was a handle leak ...
FPU in a trice: SmplMath
It's that simple!

zekyr

god damn qword. thats just beautiful

hfheatherfox07


slovach

Quote from: hfheatherfox07 on August 03, 2011, 11:19:53 PM
Hi , I came across this video on youtube http://www.youtube.com/watch?v=75AHKaSPUD8

About 17 seconds in there a Falling snow effect....

Does anybody know how that is achieved?
Or has anybody sen this before? it looks so cool

Most of those graphic effects are probably not done with OGL / DX, I'm willing to bet it's GDI (not GDI+) or DirectDraw, both can provide fast and easy access to a framebuffer for your drawing. Plus writing your own graphics engine from the ground up like that is a cool throwback to older demoscene stuff so it's popular to find in trainers etc. GDI you can use CreateDibSection() or with DirectDraw you can lock a surface for a pointer to the bits, from there you have direct access to your framebuffer.

Think of each one of your snowflakes as an object (a struct) with an x, y, and whatever else you want to influence it, like speed. Generate random starting points and for each logic tick, move them down vertically, and along a sine wave horizontally. You can skew the sine slightly to make it appear more unpredictable than a perfect wave motion.


I always liked starfields, very cool effect and simple, I've written both 3d and 2d versions of it, can post the source if anyone is interested... just be warned it's in C. The 3d one is interesting because it shows off 3d transformation, can use it as a base to a 3d software renderer.