I too would like a few pointers (not to search the forum) on how to make squares and circles with SSC...ne?
Tips&Tricks in AVS
274 posts
a=2*$pi*i;
r=1;
x=r*cos(a);
y=r*sin(a);
that'll give you a circle of radius 1.
n=5;
--------------
a=2*$pi*i+$pi/4;
r=1;
x=r*cos(a);
y=r*sin(a);
little change but that'll get you a square in one scope.
Just trig.
r=1;
x=r*cos(a);
y=r*sin(a);
that'll give you a circle of radius 1.
n=5;
--------------
a=2*$pi*i+$pi/4;
r=1;
x=r*cos(a);
y=r*sin(a);
little change but that'll get you a square in one scope.
Just trig.
A better square (in some aspects):
r=i*$pi*2;
d=1/abs(cos(asin(sin(r*2))*0.5));
x=sin(r+rot)*d+movex;
y=cos(r+rot)*d+movey;
r=i*$pi*2;
d=1/abs(cos(asin(sin(r*2))*0.5));
x=sin(r+rot)*d+movex;
y=cos(r+rot)*d+movey;
Is using two buffers faster than using an effect list?
by the way, it's for this particularly slow nightmarish thing.
<Image removed due to size. the content was also not very appropriate, even if it was intended as a joke.
- UnConeD>
- UnConeD>
little question: how can i have an effect list enabled only for a certain amount of frames?
use the override feature.
yeah i thought about that too, but any hits on how to code it? i know it's probably easy, but everything i tried didn't work.
int:
x=# of frames you want to run it for;
frame:
enabled=if(above(x,0),1,0);
x=x-1;
x=# of frames you want to run it for;
frame:
enabled=if(above(x,0),1,0);
x=x-1;
thanks a lot there 🙂
what about just
enabled=above(x,0);
Actualy I like version with the smooth alpha fadeout:
Set outpput blend to adjustable for this one 😉
enabled=above(x,0);
Actualy I like version with the smooth alpha fadeout:
...where s is (numberofframes+10)/10-- ini:
s=2;
-- frame:
alphaout=s;
enabled=above(s,0);
s=s-.1;
Set outpput blend to adjustable for this one 😉
In response to the post about 'making squares and circles' I thought I'd write a little something about creating geometry in general, with some example code of course.
For a start I'll quickly cover the 'point to point' method of creating a wireframe object. The idea is one that I've been using since I came into AVS (remember that dodecahedron anyone?) The basic idea is that you increment a counter every time you draw a point and then use this value with conditional structures to decide what should be drawn for each individual point. Example:
(Lines SSC)
init:
// Square
n=5;
frame:
// Set our point counter to 0
counter = 0;
// Calculate aspect ratio of AVS display (unimportant)
aspectratio = h/w;
beat:
<nothing>
point:
/*
Basically for each point we want to draw we have a section
in this big expresion for x (and also in the later y expression).
For example, when the first point is drawn counter = 0 so the
'first line' sets x = 1 when counter = 0 since 1 is the x coord of
our desired first point for the square. This is repeated for every
possible value of counter until all of the required x-coords have
been assigned. Since nothing is done if counter != 0 for the
'first line' we can add the subsequent expressions without
affecting any of the other points.
*/
x = 1 * equal(counter,0)
+ 1 * equal(counter,1)
+ -1 * equal(counter,2)
+ -1 * equal(counter,3)
+ 1 * equal(counter,4);
y = -1 * equal(counter,0)
+ 1 * equal(counter,1)
+ 1 * equal(counter,2)
+ -1 * equal(counter,3)
+ -1 * equal(counter,4);
// Scale the square so we can see the top and bottom edges (unimportant)
x=x*.5;y=y*.5;
// Increment the point counter
counter = counter + 1;
// Correct aspect ratio (unimportant)
x = x* aspectratio;
(End SSC)
Note that 5 points are used since AVS needs two points to draw a line so the first line goes from counter=0 to counter=1, the second from counter=1 to counter=2, the third from counter=2 to counter=3 and the final one from counter=3 to counter=4 (which is the same as counter=0 for all intents and purposes). You can optimise and tidy this up a lot, I just made a big mess to make everything as clear as possible.
This method is great for a lot of objects and can be extended to 3D wireframes pretty easily (see 'Golden Dodecahedron' from Jheriko - Pack VI for an example of this done with a slightly different implementation (ifs instead of equals)). However we can't draw a circle from it or a sphere either.
When you want to draw curved surfaces in AVS you have to use some maths and typically this can be difficult if you don't already know the answer. Most of us for instance know that x=sin(2*$PI*i);y=cos(2*$PI*i); creates a circle.. but why does this work? Well, you can get this from experimentation (which is how I first figured this out when I started at qbasic.. guesswork) but a much better way is logic. There is no generic way to get an equation for a shape, however some common sense and a good knowledge of maths will help a lot. For instance I can say that
x=sin(t), y=cos(t)
is clearly a circle due to the trig identity
sin(t)^2 + cos(t)^2 = 1
so the hypotenuse of the triangle made by the points (0,0) (x,0) (x,y) is always going to be 1 (draw a diagram if you can't see this), and so this hypotenuse is always going to be the radius of a unit circle about the origin. Make sense?
Lets assume for a moment that we have no idea about how to make a sphere. It would seem logical that we can somehow extend the circle definition into three dimensions to get a sphere. This infact can be done by using the sin(t)^2+cos(t)^2=1 identity.
sin(t)^2 + cos(t)^2 = 1
sin(u)^2 + cos(u)^2 = 1
multiplying these together gives us something which still = 1
sin(t)^2 sin(u)^2 + cos(t)^2 sin(u)^2 + sin(t)^2 cos(u)^2 + cos(t)^2 cos(u)^2 = 1
However this has four 'components' so we must eliminate one of them to get something we can equivalate to the x^2+y^2+z^2=1 which defines a unit sphere.
Noting that sin(t)^2 + cos(t)^2 = 1 and combining the last two 'components' together:
sin(t)^2 sin(u)^2 + cos(t)^2 sin(u)^2 + (sin(t)^2 + cos(t)^2)cos(u)^2 = 1
sin(t)^2 sin(u)^2 + cos(t)^2 sin(u)^2 + cos(u)^2 = 1
taking each of these components and equivalating them to x^2+y^2+z^2=1 we get
x=sin(t)sin(u);
y=cos(t)cos(u);
z=cos(u);
The actual definitions of t and u in code will affect which points are drawn and a simple relation like t=2*u will create a specific curve which looks little like a sphere, using something like t=200*u will create a 'spiral sphere' type shape.
When trying to make a specific shape when you can't find an equation for it the best approach is to start with what you know about that shape and then exploit that with your mathematical knowledge to create a parameterisation. Another good example would be a torus. The idea I used to make 'Space Torus' in Jheriko - Pack VIII was simply to define a circle with the torus minor radius and shift it along an axis by the major radius then to perform a matrix rotation on this to 'sweep out' a torus. All I had to do was use the appropriate rotation matrix out of the 3D transformation from the SSC to multiply with the existing offset circle definition then to use a second parameter to tell it how much to rotate by rather than using a fixed value every frame.
Often once you have found a basic shape that works you can modify it too. Playing around with an equation can create interesting effects, sometimes some logical thought process can help here too, for instance the method I described for the torus above can be easily extended to create other shapes by using different rotations or initial shapes, these shapes will often be a lot more interesting because you decided to try it out for some reason... rather than just blundering upon it by random code changes.
Remember that figuring something out for yourself will often give you a much deeper understanding of it than just 'learning it from a book'.
If you find it really difficult to come up with your own shapes, or to convert your knowledge of a shape into code, then take a look around the internet on math resourse sites and such, you are bound to find some interesting parametric shapes eventually.
Hope this helps someone out.
For a start I'll quickly cover the 'point to point' method of creating a wireframe object. The idea is one that I've been using since I came into AVS (remember that dodecahedron anyone?) The basic idea is that you increment a counter every time you draw a point and then use this value with conditional structures to decide what should be drawn for each individual point. Example:
(Lines SSC)
init:
// Square
n=5;
frame:
// Set our point counter to 0
counter = 0;
// Calculate aspect ratio of AVS display (unimportant)
aspectratio = h/w;
beat:
<nothing>
point:
/*
Basically for each point we want to draw we have a section
in this big expresion for x (and also in the later y expression).
For example, when the first point is drawn counter = 0 so the
'first line' sets x = 1 when counter = 0 since 1 is the x coord of
our desired first point for the square. This is repeated for every
possible value of counter until all of the required x-coords have
been assigned. Since nothing is done if counter != 0 for the
'first line' we can add the subsequent expressions without
affecting any of the other points.
*/
x = 1 * equal(counter,0)
+ 1 * equal(counter,1)
+ -1 * equal(counter,2)
+ -1 * equal(counter,3)
+ 1 * equal(counter,4);
y = -1 * equal(counter,0)
+ 1 * equal(counter,1)
+ 1 * equal(counter,2)
+ -1 * equal(counter,3)
+ -1 * equal(counter,4);
// Scale the square so we can see the top and bottom edges (unimportant)
x=x*.5;y=y*.5;
// Increment the point counter
counter = counter + 1;
// Correct aspect ratio (unimportant)
x = x* aspectratio;
(End SSC)
Note that 5 points are used since AVS needs two points to draw a line so the first line goes from counter=0 to counter=1, the second from counter=1 to counter=2, the third from counter=2 to counter=3 and the final one from counter=3 to counter=4 (which is the same as counter=0 for all intents and purposes). You can optimise and tidy this up a lot, I just made a big mess to make everything as clear as possible.
This method is great for a lot of objects and can be extended to 3D wireframes pretty easily (see 'Golden Dodecahedron' from Jheriko - Pack VI for an example of this done with a slightly different implementation (ifs instead of equals)). However we can't draw a circle from it or a sphere either.
When you want to draw curved surfaces in AVS you have to use some maths and typically this can be difficult if you don't already know the answer. Most of us for instance know that x=sin(2*$PI*i);y=cos(2*$PI*i); creates a circle.. but why does this work? Well, you can get this from experimentation (which is how I first figured this out when I started at qbasic.. guesswork) but a much better way is logic. There is no generic way to get an equation for a shape, however some common sense and a good knowledge of maths will help a lot. For instance I can say that
x=sin(t), y=cos(t)
is clearly a circle due to the trig identity
sin(t)^2 + cos(t)^2 = 1
so the hypotenuse of the triangle made by the points (0,0) (x,0) (x,y) is always going to be 1 (draw a diagram if you can't see this), and so this hypotenuse is always going to be the radius of a unit circle about the origin. Make sense?
Lets assume for a moment that we have no idea about how to make a sphere. It would seem logical that we can somehow extend the circle definition into three dimensions to get a sphere. This infact can be done by using the sin(t)^2+cos(t)^2=1 identity.
sin(t)^2 + cos(t)^2 = 1
sin(u)^2 + cos(u)^2 = 1
multiplying these together gives us something which still = 1
sin(t)^2 sin(u)^2 + cos(t)^2 sin(u)^2 + sin(t)^2 cos(u)^2 + cos(t)^2 cos(u)^2 = 1
However this has four 'components' so we must eliminate one of them to get something we can equivalate to the x^2+y^2+z^2=1 which defines a unit sphere.
Noting that sin(t)^2 + cos(t)^2 = 1 and combining the last two 'components' together:
sin(t)^2 sin(u)^2 + cos(t)^2 sin(u)^2 + (sin(t)^2 + cos(t)^2)cos(u)^2 = 1
sin(t)^2 sin(u)^2 + cos(t)^2 sin(u)^2 + cos(u)^2 = 1
taking each of these components and equivalating them to x^2+y^2+z^2=1 we get
x=sin(t)sin(u);
y=cos(t)cos(u);
z=cos(u);
The actual definitions of t and u in code will affect which points are drawn and a simple relation like t=2*u will create a specific curve which looks little like a sphere, using something like t=200*u will create a 'spiral sphere' type shape.
When trying to make a specific shape when you can't find an equation for it the best approach is to start with what you know about that shape and then exploit that with your mathematical knowledge to create a parameterisation. Another good example would be a torus. The idea I used to make 'Space Torus' in Jheriko - Pack VIII was simply to define a circle with the torus minor radius and shift it along an axis by the major radius then to perform a matrix rotation on this to 'sweep out' a torus. All I had to do was use the appropriate rotation matrix out of the 3D transformation from the SSC to multiply with the existing offset circle definition then to use a second parameter to tell it how much to rotate by rather than using a fixed value every frame.
Often once you have found a basic shape that works you can modify it too. Playing around with an equation can create interesting effects, sometimes some logical thought process can help here too, for instance the method I described for the torus above can be easily extended to create other shapes by using different rotations or initial shapes, these shapes will often be a lot more interesting because you decided to try it out for some reason... rather than just blundering upon it by random code changes.
Remember that figuring something out for yourself will often give you a much deeper understanding of it than just 'learning it from a book'.
If you find it really difficult to come up with your own shapes, or to convert your knowledge of a shape into code, then take a look around the internet on math resourse sites and such, you are bound to find some interesting parametric shapes eventually.
Hope this helps someone out.
I learned creating AVS from Tips&Tricks.Thanks
Fastest rectangle similiar to the window, ready to be scaled (maybe rotated) :
INIT: n=5
FRAME: p=0;
PIXEL:
p=p+1;
x=(p-1)&2-1;
y=p&2-1;
linesize=a;
[aspect ratio]
[rotation]
...Where a is the pixel size that you wish.
(Consider multiplying both x and y by 1-{1/[h or w, accordingly]} so that the pixel difference between the top-left and bottom-right is nulled.)
INIT: n=5
FRAME: p=0;
PIXEL:
p=p+1;
x=(p-1)&2-1;
y=p&2-1;
linesize=a;
[aspect ratio]
[rotation]
...Where a is the pixel size that you wish.
(Consider multiplying both x and y by 1-{1/[h or w, accordingly]} so that the pixel difference between the top-left and bottom-right is nulled.)
you forgot some brackets there 🙂
and it can still be optimized 😉
x=(p&2)-1;
p=p+1;
y=(p&2)-1;
and it can still be optimized 😉
x=(p&2)-1;
p=p+1;
y=(p&2)-1;
thanx man
this generates a fancy colorcycling triangle without any ifs or equals 🙂
// SuperScope:
// Frame:
x1=-.5; y1=-.5;
x2=.8; y2=-.3;
x3=.1; y3=.6;
n=w+h;
t=gettime(0);
facx1=x2-x1; facy1=y2-y1;
facx2=x3-x2; facy2=y3-y2;
facx3=x1-x3; facy3=y1-y3;
// Point:
i1=i*3; i2=i1-1; i3=i1-2;
i1=min(1,max(0,i1)); i2=min(1,max(0,i2)); i3=min(1,max(0,i3));
x=x1 + i1*facx1 + i2*facx2 + i3*facx3;
y=y1 + i1*facy1 + i2*facy2 + i3*facy3;
red=sin(i*80+t*10)/2+.5;
green=1-red;
blue=red;
Someone might find it useful. Anyone?
a lot of formulae there, you're right... problem is that it's listed by name/category, so you have to know the name/category to find a formula... but thanks for the link i think i'm just gonna try random 4th degree polynomials with raytracing 😁
Is there any way to use the effects list override to filter out certain wavelengths of sound, so you only get bass through or treble?
Any help would be good...
Any help would be good...
Mr_Nudge, you could use getspec or getosc for detecting the sound values and then just use the "evallib override" in the effect list. But there is a problem with that, because every song is different and one getosc/getspec setting would detect your desired values on one song and completly something else on some other (if you're even that lucky you manage to find the exact value for those which i highly doubt)
Perfect or even good bass/beat detection is said to be impossible even with the supercomputers of today 🙂
Perfect or even good bass/beat detection is said to be impossible even with the supercomputers of today 🙂
you cannot change the waveform 🙂
all you can do is read it and then change the variables you store it in.
all you can do is read it and then change the variables you store it in.
Tug: good beat detection is perfectly possible, but it would require more CPU time. I know, cos I had to make a good beat detector for a univ project 😉.
My approach: do an FFT per N samples, and calculate the autocorrelation in time of these FFTs. The shift at which the correlation is highest (except of course zero shift) is usually a multiple of the bpm.
My approach: do an FFT per N samples, and calculate the autocorrelation in time of these FFTs. The shift at which the correlation is highest (except of course zero shift) is usually a multiple of the bpm.
if you want to create a radial gradient out of (y=i;x=0) superscope, put a movement after it:
🙂r=atan2(0,-abs(y))
Global nullifier & scrambler
Two emtpy presets with one superscope. The other nullifies (sets to zero) all global vars and the other gives them random values between 0-999.
Someone just had to wrote them 🙄
Useful for debuggin your presets, or just copy the nullifier lines to your own preset.
Two emtpy presets with one superscope. The other nullifies (sets to zero) all global vars and the other gives them random values between 0-999.
Someone just had to wrote them 🙄
Useful for debuggin your presets, or just copy the nullifier lines to your own preset.
Ok, another effects list question:
how would you get an effects list to enable only when there's music playing, i've tried using
enabled=if((above(getspec(1,0.1,0)),1),1,0)
but it doesn't work. By the way i'm not that good at avs code, but for what i do know this looks like it should work.
how would you get an effects list to enable only when there's music playing, i've tried using
enabled=if((above(getspec(1,0.1,0)),1),1,0)
but it doesn't work. By the way i'm not that good at avs code, but for what i do know this looks like it should work.
you could check playpos using gettime(-1) and see if it changed in the last frame
even more optimized ^^
or optimized:
lpos=pos;
pos=gettime(-1);
enabled=1-equal(pos,lpos);
[edit]
lpos=pos;
enabled=1-equal(lpos,assign(pos,gettime(-1)));
even more optimized ^^
the +0 is needed so equal() wont read its first input value from pos, but from a temporary buffer
enabled=1-equal(pos+0,assign(pos,gettime(-1)));
Try using enabled=if(above(getspec(0,.5,0),a),1,0); instead. I used "a" because you can set the treshold if you wish(between 0 and 1). The lower the number, the more often the effect list is enabled.
What you did wrong was to return 1 when the getspec data is above 1, which is never. I replaced it with 0. Also, you based the data on getspec(1,0.1,0) which looks at a narrow band in the higher pitches.
If I were you I would add some code to change the blend level so it can blend in and out of volume levels.
What you did wrong was to return 1 when the getspec data is above 1, which is never. I replaced it with 0. Also, you based the data on getspec(1,0.1,0) which looks at a narrow band in the higher pitches.
If I were you I would add some code to change the blend level so it can blend in and out of volume levels.