Archive: randomly reversing x-direction Trans/Dynamic Movement?


2nd October 2008 13:02 UTC

randomly reversing x-direction Trans/Dynamic Movement?
Hullo all again.

I have a very basic query that is hurting me now after several hours of experimentation.
Essentially, I am using Trans/Dynamic Movement to change the speed and direction of a Superscope randomly along the x-plane, wo far with limited success. It was easy to get it to change from 0 to either -1 or +1 but not both a neg or pos val together.

The basic structure of the move I am using is: x=x-1/16 ;med speed move to the right.

So in Beat this:
randspeed=rand(64)+16; (works fine)
randdir=rand(2)-1; SHOULD random an interger between 0 and 2 and then subtract 1 so I am left with a spread of possible -1,0,+1. (right/nil/left movement)

In Pixel, this:
x=x+randdir/randspeed;

Unfortunately, this will only garner results that lean to moving everything either to the right or not at all. For some reason X=X+RANDDIR only ends up with a negative value making for movement to the right and it's driving me insane. The only way to change it to move left is to fiddle the +'s and -'s which is just not right lol.
Any ideas anyone? Searching the forums did not evoke anyting as neither did dismantling many other avs's. Essentially I am not trying to move the scope, but the falloff generated by it (well, the previously drawn frames of it).

Grateful for any help.
Cheers, nNem.


2nd October 2008 13:35 UTC

Try this;

Beat:
m=(rand(2000)-1000)/1000;

Pixel:
x=x+m;

:)


2nd October 2008 15:18 UTC

Hi, nNemethon!

Rand(x) gives you a random number within the range of x integers, starting from zero (not starting from one).
So, for rand(2), that's 0 or 1.
If you want to include 2, that gives you three integers: 0,1 and 2.
It's a common misunderstanding.

So, your code should read:

randspeed=rand(64)+16;
randdir=rand(3)-1;
---
x=x+randdir/randspeed;

QOAL's method is better though: by allowing a negative speed you don't need the direction anymore.

Be sure to divide it by more than thousand though (I suggest a number between 10000 and 100000), or it will shift half a window (max) with each frame.


2nd October 2008 16:03 UTC

example file added


3rd October 2008 11:48 UTC

Champion guys, big star and a thank you for both of you. :)

QOAL: Different way of doing things in a simpler, faster design. I had never thought of a negative speed as I was focused on getting that negative direction jammed in there via linear thinking. :)

Warrior: Very good explanation of the rand() fuction call. As I understood the basic instructs within the avs editor, rand(2) encompassed 0,1&2 - not the actuality of 'highest final is closed' order being 0&1 only. I had seen examples for a random colour eg. rr=rand(256)/255... and was trying to work out why they were pushing a for a decimal where it was worthless.
Regarding QOAL's instructs, I went for that immediately as I already explained, with being neater and looks more impressive too :D. I also bumped up the diviser to 40,000 and is working a charm. I also had a good long look at the supplied zip and so now I can do a quick circle. :D It's also given me ideas of how to better organise lists and routines while being nice and neat and readable so thanks once again. :)

Now all I need to do is work out how to get several layers in parallax to fake a 3d and then how to make a real 3d in volumetric space. :)

Cheers.
nNem


3rd October 2008 15:24 UTC

glad to help :up:

check out the tutorials here