Archive: Superscope newbie question


31st August 2003 18:48 UTC

Superscope newbie question
I'm new to this whole AVS thing so I'm not too familiar with all of the math commands available (I have no trouble with the purely mathematical part of it, just the notation used and stuff like that).
What I want to know is, how do I make logic statements like
IF l>f
THAN
l=l-f
ELSE
l=l+1
Any help with how to make statements like that in the superscope would be greatly appreciated.


31st August 2003 19:46 UTC

I think this is what you need (I'll use X and Y for variables):

x=if(below(x,y),x-y,x+1)

That should work... have you read the Expression Help thoroughly? That explains it as well, if I remember correctly.

Hey look... my first post in HOW long? :)

EDIT: OK, here's a concise explanation of the operators:
-In the statement x=if(x,y,z) x is the condition. There are several conditions, the ones most commonly used being above, below, and equal. I will explain these in a sec, but for now, just know that if the condition is true (1), then the if(...) statement returns y. If the condition is false (0), then it returns z.
-The conditions:
> above(a,b) returns 1 if a>b, 0 if a<b
> below(a,b) returns 1 if a<b, 0 if a>b
> equal(a,b) returns 1 if a=b, else 0

Hope that helps.


31st August 2003 21:27 UTC

The if(x,y,z) statement will return y with any non-zero number for x. You can also you the bor(x,y) and band(x,y) statements for boolean and and or operators. Search the forums for more information.


31st August 2003 21:32 UTC

to your vars:

l=if(above(l,f),l-f,l+1);

var = if(statement,statement true, statement not true);


1st September 2003 00:05 UTC

no offense...but i would think anyone who was actually into logical programming would know the difference between "then" and "than"...


1st September 2003 16:31 UTC

:p Let's just call it a typo ;)


1st September 2003 20:28 UTC

Oh nertz... I just realized that it should have been "above" and not "below". Thanks Deamon. :)


2nd September 2003 06:05 UTC

Remember also what UnConeD mentioned a while back ago that AVS calculates both y&z regardless of x, so if there is a way around using the logical statements, use it.


3rd September 2003 09:10 UTC

you're welcome, glad I could help you.


3rd September 2003 09:53 UTC

Originally posted by Tuggummi
If there is a way around using the logical statements, use it.
Can you give me example code for that? I cant imagein where this would be possible (or would make sense, atleast its always possible)

3rd September 2003 11:10 UTC

I did say IF did i? :weird:
IF there is a way around it. It's up to the situation & effect desired wheter or not it can be done without the statements, but yes i can't imagine any example situations either or a way around it...

[edit]
Well i can think up of one simple example...
If you want for example: var=if(equal(var2,var3),1,0) you can just do it with var=equal(var2,var3) to avoid using the if statement. And if you want something like var=if(equal(var2,var3),1.378914,0) then you can just multiply the equal(var2,var3) with 1.378914.

A simple scope examle:

per beat:
color=rand(3) ;

per frame:
red=equal(color,0) ; green=equal(color,1) ; blue=equal(color,2)

per pixel:
x=i*2-1 ;
y=v ;


This will create a simple oscilliscope analyzer that changes onbeat between the red,green & blue colors, if color=2 it will change to blue as in rgb: 0,0,255.

This is just a small & very simple example and i can't think of any other examples, but still it's best to think about the code structure a bit rather than just use stacks&stacks of code, because it's easier :p
[/edit]


3rd September 2003 12:41 UTC

Okay, it works as long as one condition can be zero.

But take this one:

x=if(above(x,0.5),x-0.2,x+0.2);

Would be:

x=x-above(x,0.5)*0.2+bnot(above(x,0.5))*0.2;

This is more likely to be slower than faster!


3rd September 2003 19:26 UTC

Magic.X: Instead of using bnot(above(x,0.5)), wouldn't it be faster to use below(x,0.5)? If x>0.5 then the 'above' statement would return 1 and the 'below' statement would return 0, and if x<0.5 it would be the other way around, correct?


4th September 2003 07:09 UTC

As magic pointed out, it works as long as one condition can be zero AND as long as you're doing it with numbers only. When you involve the x,y,r & d coordinates it gets tricky, might be impossible even, but as i know someone comes and proves me wrong as soon as i say it, so im not saying it :p

The reason why it doesn't work is because you need two different conditions above&below of the certain point in the x-axis. If you just use x=x+above(x,0.5)-below(x,0.5) it... well see for yourself :igor: i can't explain & don't even know what it does exactly, but it doesn't work.

All im saying is that try to "code wisely"... and i can't believe how much text i have to spill out just because i wanted to say that :blah:


4th September 2003 09:28 UTC

above, below, and equal provide BOOLEAN RESULTS, which by using BOOLEAN MATHS can solve logical equations. Example:

a > b AND c > d == above(a,b)*below(c,d)
a >= b OR c < d == above(0,(1-below(b,a)) + below(c,d))

:D


4th September 2003 09:35 UTC

originally posted by a stupid idiot:

The reason why it doesn't work is because you need two different conditions above&below of the certain point in the x-axis. If you just use x=x+above(x,0.5)-below(x,0.5) it... well see for yourself i can't explain & don't even know what it does exactly, but it doesn't work.
Actually i just tested it, it does work :igor: But is it any faster... i doubt so :igor:

I'll shut my mouth now.

5th September 2003 10:28 UTC

Lol@ Tugg :p

It isnt the same anyway because clinical ttreated the x=0.5 case diffrently then i did.

The point goes to then global fonze ;)

You can solve anything with boolena math, which is exactly what is done within the cpu! It can only differ between current and no current.

This may be even a tiny bit faster but requires a better logical understanding.

But hey, what are we argueing about? 0.005 fps diffrence?? :blah:
Lets forget about it, hey. I like my code to be easy understandable (although i dont code that much). ;)


5th September 2003 13:09 UTC

Magic.X: the difference can be quite big

For scopes that alternate between complex shapes, it's often best to make separate scopes, and set n to 0 for all but one. This calculates only one shape per frame rather than all shapes.

You could even do this for interpolation: implement a scope for any change between any two scopes, though that would be quite big for any reasonable amount of shapes.