djcoolman
20th June 2002 18:49 UTC
Switch
a function that switching 2 numbers or more every beat or avry frame.
EG:-
on beat:
rnd=switch(10,5);
EG:-
on beat:
rnd=switch(num,num1,num2);
num=rand(10);
num1=rand(10);
num2=rand(10);
and slow fade:
in DM's i want 2 do fade.
so it gona be slowly gone and slowly come back.
i know that i can do it with alpha but its compliceted.
UnConeD
21st June 2002 00:13 UTC
Complicated vs. powerful
Both things you mention are perfectly possible, but you seem to want an easy solution because AVS's way of doing it is too complex...
Well don't know about you, but I prefer powerful vs. easy to a certain degree.
If you want to switch between two numbers, you can use an alternating condition. For example:
c=bnot(c);
Every time this statement is executed, the value of 'c' is negated. If it is true (non-zero), then it becomes false (zero) and vice-versa. If you don't initialise 'c' yourself, it will start out 0, which means false.
So suppose that you wanted a movement to alternate between a fast and slow zoom, you could use:
Onbeat:
c=bnot(c);
Pixel:
d=d*if(c,.95,.85);
In fact you seem to be a bit intimidated by AVS's powerful scripting abilities. A good place to start is to try and copy AVS's built-in effects. The little zoom code above is a good example of how to imitate a "Blitter Feedback". Once you know how to do basic effects, you can combine them into new, complicated things.
Something that is interesting to know is when you want a variable (e.g. a zoom factor) to move towards a new value rather than jumping to it.
Suppose your target value is "vt" and your current value is "vc". You could use:
vc=vc*0.8+vt*0.2
What this code does is replace 20% of 'vc' value with vt's value. This is easy to understand with a numeric example. Suppose vc starts out as 0 and vt as 1, then the value of vc will evolve like this every time the statement is executed:
0, (0*0.8 + 0.2) = 0.2, (0.2*0.8 + 0.2) = 0.36, (0.36*0.8 + 0.2) = 0.488, 0.5904, ...
You can see how it moves towards the target value. Notice too that the jumps between 2 values decrease as 'vc' gets closer to 'vt'.
Suppose you wanted it to change value at a constant rate though. You could use:
vc=vc + 0.1*sign(vt-vc);
Let's see what's going on. The sign() function returns '1' for positive numbers, and '-1' for negative numbers. So we first check the sign of (vt-vc), to see if we need to go up or down. Then, we use the result of sign(), multiply it by 0.1 and add it to our existing value.
In our previous example (vc=0, vt=1), vc will evolve linearly:
0, 0.1, 0.2, ..., 0.9, 1
There's a small problem with this code though: it doesn't stop. So suppose your 'vc' was 0, and 'vt' was 0.15. Then vc will evolve like this:
0, 0.1, 0.2, 0.1, 0.2, 0.1, 0.2, ...
. As you can see, it 'wobbles' around the value, because it becomes too large after the jump from 0.1 to 0.2.
To prevent this, you could check if the distance between vc and vt is less than the jump value (0.1 in our case), and if it is, we jump directly to vt because we're close enough.
Our new improved code is:
vc=if(below(abs(vt-vc),0.1),vt,vc+0.1*sign(vt-vc));
djcoolman
21st June 2002 07:17 UTC
Sorry but i still think that its a good idea.
cos i anderstand only half of that.