3 planar rotations are what you might call "3D rotation"
btw you could cache the cosines and sines for optimization, since (co)sine is a very expensive operation
look at that other thread you opened for info on how to optimize the divisions
Tips&Tricks in AVS
274 posts
A surrealistic thing: this looks like a star.
init
n=k0*600; tpi=2*acos(-1);
point
d=k1*v+i*tpi; x=x0+pow(cos(d),3)*kx; y=y0+pow(sin(d),3)*ky;
k0, k1, kx, ky, x0, y0 are optional values, they equal to 0 (x0, y0) or 1 (k) by default;
If this is well-known, I post it for reference.
This is a bit oldschool, isn't it?
Thanks🙄
init
n=k0*600; tpi=2*acos(-1);
point
d=k1*v+i*tpi; x=x0+pow(cos(d),3)*kx; y=y0+pow(sin(d),3)*ky;
k0, k1, kx, ky, x0, y0 are optional values, they equal to 0 (x0, y0) or 1 (k) by default;
If this is well-known, I post it for reference.
This is a bit oldschool, isn't it?
Thanks🙄
a bit misplaced maybe, since this is about tips&tricks and not about specific scopes
things like rotation are used in many presets and in many different scopes, texers, DMs and whatnot
in other words: rotation is part of the basics. your scope is not
things like rotation are used in many presets and in many different scopes, texers, DMs and whatnot
in other words: rotation is part of the basics. your scope is not
Originally posted by UIUC85
int:
x=# of frames you want to run it for;
frame:
enabled=if(above(x,0),1,0);
x=x-1;
dont write things like if(boolean expression,1,0)
the if there is superfluous, since above returns 1 for true and 0 for false (as documented)
Originally posted by Warrior of the LightSorry, but I just can't ignore that ugliness anymore. Here, try this instead:
Triangular wave for an SSC:
x=i*2-1;
y=asin(sin(i*$pi*2))/asin(1);
There. Thank goodness for the floor() function!x=i*2-1;
ii=i-.25;
y=abs((ii-floor(ii))*2-1)*2-1;
Raytracing...
I keep teaching people how to raytrace... so this time I made a half decent resource:
I keep teaching people how to raytrace... so this time I made a half decent resource:
I need an advice on time-based evaluation.
eg set=rand(n) is evaluated approx. every 5 seconds.
m1=equal(set,1);
m2=equal(set,2);... go on after 'set' changes.
I used to make expressions like
change=bor(below(t*k-floor(t*k),deltat*0.5),above(t*k-floor(t*k),1-deltat*0.5));
with t*k-floor(t*k)(main expression), deltat*0.5 cached at the beginning, in timer based on expression timer=t*k-floor(t*k).
It works, but is too approximate, even more: this timer automates one variable, and cannot randomize.
And it seems the best solution is to work on custom BPM:
Skip 7 beats.
eg set=rand(n) is evaluated approx. every 5 seconds.
m1=equal(set,1);
m2=equal(set,2);... go on after 'set' changes.
I used to make expressions like
change=bor(below(t*k-floor(t*k),deltat*0.5),above(t*k-floor(t*k),1-deltat*0.5));
with t*k-floor(t*k)(main expression), deltat*0.5 cached at the beginning, in timer based on expression timer=t*k-floor(t*k).
It works, but is too approximate, even more: this timer automates one variable, and cannot randomize.
And it seems the best solution is to work on custom BPM:
Skip 7 beats.
yay random code for the win
Originally posted by The Earthquaker
I need an advice on time-based evaluation.
eg set=rand(n) is evaluated approx. every 5 seconds.
m1=equal(set,1);
m2=equal(set,2);... go on after 'set' changes.
I used to make expressions like
change=bor(below(t*k-floor(t*k),deltat*0.5),above(t*k-floor(t*k),1-deltat*0.5));
with t*k-floor(t*k)(main expression), deltat*0.5 cached at the beginning, in timer based on expression timer=t*k-floor(t*k).
It works, but is too approximate, even more: this timer automates one variable, and cannot randomize.
And it seems the best solution is to work on custom BPM:
Skip 7 beats.
its like three totally disconnected statements glued together...
Wow, when i made this long-long time ago i thought this would bring all neat or often used tricks and whatnot together to a nice package, but now it seems that this is more cluttered than the AVS forums itself 🧟
In short, this thread makes little sense anymore 😛
In short, this thread makes little sense anymore 😛
it needs a refresh indeed.. .pdf anyone? 😛
Question: How do you get the liquid effect using a dm?
Originally posted by The EarthquakerI want to apologize for that though I thought I make a post with intro and outro.
I need an advice on time-based evaluation.
...
And it seems the best solution is to work on custom BPM:
Skip 7 beats.
The stuff that is sandwiched beetween is what I meant a general question.
Originally posted by The Earthquakeri still didnt get the idea. there is gettime() if you want something to be dependent on a timer...
I want to apologize for that though I thought I make a post with intro and outro.
The stuff that is sandwiched beetween is what I meant a general question.
eeltrans macros for HSL -> RGB conversion:
// --- HSL ---Usage:
// converts from HSL color space to RGB color space
#define HSL2RGB(H,S,L,R,G,B) (var_2=if(below(L,.5),L * ( 1 + S ),( L + S ) - ( S * L ));var_1=2 * L - var_2;R=Hue_2_RGB(var_1,var_2,H+third);G=Hue_2_RGB(var_1,var_2,H);B=Hue_2_RGB(var_1,var_2,H-third))
// initialization macro for HSL2RGB
#define init_HSL2RGB() third=1/3;
// helper macro for HSL2RGB - needs wrap()
#define Hue_2_RGB(v1,v2,invH) (vH=invH;wrap(vH, 0, 1, 1); v6H=6*vH; if(below(v6H, 1), v1+(v2-v1)*v6H, if(below(2*vH, 1), v2, if(below(3*vH, 2), v1+(v2-v1)*(4-v6H), v1))))
// wraps a value between minval and maxval. range should be (maxval-minval)
#define wrap(var,minval,maxval,range) if(below(var,minval),var=var+range,if(above(var,maxval),var=var-range,0));
hue=.3;
sat=1;
lum=.5;
HSL2RGB(hue,sat,lum,red,green,blue);
Anybody could they say why the code is so unefficient...
Its purpose was to draw a border with length halfx*2, width halfy*2, and this code is supposed to be optimised. SuperScope, n=535.
//init
halfx=100; halfy=50; opts=0.5/(halfx+halfy); sqd=sqr(opts);
rej1=opts*halfx; rej2=opts*halfy;
//frame
rlw=halfx/w; rlh=halfy/h;
//point
x=if(above(i,rej1),if(above(i,0.5),if(above(i,0.5+rej1),-rlw,(i-0.5)*n*halfx*sqd*2-rlw),rlw),i*n*halfx*sqd*2-rlw);
y=if(above(i,rej1),if(above(i,0.5),if(above(i,0.5+rej1),(i+rej2-1)*n*halfy*sqd*4-rlh,rlh),(i-rej1)*n*halfy*sqd*4-rlh),-rlh);
Its purpose was to draw a border with length halfx*2, width halfy*2, and this code is supposed to be optimised. SuperScope, n=535.
//init
halfx=100; halfy=50; opts=0.5/(halfx+halfy); sqd=sqr(opts);
rej1=opts*halfx; rej2=opts*halfy;
//frame
rlw=halfx/w; rlh=halfy/h;
//point
x=if(above(i,rej1),if(above(i,0.5),if(above(i,0.5+rej1),-rlw,(i-0.5)*n*halfx*sqd*2-rlw),rlw),i*n*halfx*sqd*2-rlw);
y=if(above(i,rej1),if(above(i,0.5),if(above(i,0.5+rej1),(i+rej2-1)*n*halfy*sqd*4-rlh,rlh),(i-rej1)*n*halfy*sqd*4-rlh),-rlh);
Originally posted by The EarthquakerI am going to start from the bottom up rather than the top down so that you can fully comprehend the totality of your failure.
Anybody could they say why the code is so unefficient...
1.) Cache some multiplies to remove per point muls:
//frame
rlw=halfx/w; rlh=halfy/h;
opt=2*n*sqd;
//point
x=if(above(i,rej1),if(above(i,0.5),if(above(i,0.5+rej1),-rlw,(i-0.5)*opt*halfx-rlw),rlw),i*opt*halfx-rlw);
y=if(above(i,rej1),if(above(i,0.5),if(above(i,0.5+rej1),(i+rej2-1)*opt*halfy*2-rlh,rlh),(i-rej1)*opt*halfy*2-rlh),-rlh);
2.) Don't use points to draw lines when there is a line tool available. The 'lines' superscope option enables a c++/asm line drawing routine, this is orders of magnitude faster than any evallib routine...
// innit
n=4;
halfx=100; halfy=50;
// frame
rlw=halfx/w; rlh=halfy/h;
c=0;
//point
x=if(c%2,rlw,-rlw);
y=if(above(c,1),rlh,-rlh);
c=c+1;
3.) Make it do what its supposed to, notice how the rectangle resizes in a crazy way when you resize the window, you need aspect ratio correction.
// innit
n=4;
halfx=100; halfy=50;
// frame
asp=h/w;
rlw=halfx/w;
rlh=halfy/h;
c=0;
//point
x=if(c%2,rlw,-rlw);
y=if(above(c,1),rlh,-rlh);
c=c+1;
Can I change thses values t=reg11;
e=equal(t,-1);
ym=if(e,(rand(20)-10)*-.1,ym);
xm=if(e,(rand(20)-10)*.1,xm);
reg22=ym;
to: g=abs(getosc(.7,.3,0));
s=if(above(g,s*.5),s+.03,s-.03);
ym=if(below(ym,-1),1,ym-.01);
xt1=xt1+.0277;
xb2=xb2*.98; xt2=xt2+xb2;
For getting trigonometry around together?
e=equal(t,-1);
ym=if(e,(rand(20)-10)*-.1,ym);
xm=if(e,(rand(20)-10)*.1,xm);
reg22=ym;
to: g=abs(getosc(.7,.3,0));
s=if(above(g,s*.5),s+.03,s-.03);
ym=if(below(ym,-1),1,ym-.01);
xt1=xt1+.0277;
xb2=xb2*.98; xt2=xt2+xb2;
For getting trigonometry around together?
1. What the HELL is that?
2. trigonometry?
3. What the hell is THAT?
4. Did you read PAK-9's AVS Programming Guide?
5. What the hell IS that?
6. oh and btw, stealing code without crediting is BAAAAD, ok?
2. trigonometry?
3. What the hell is THAT?
4. Did you read PAK-9's AVS Programming Guide?
5. What the hell IS that?
6. oh and btw, stealing code without crediting is BAAAAD, ok?
Originally posted by Red MulletThey should put that on a t-shirt... seriously though, can we please refrain from asking random questions on this thread. I shouldn't have encouraged it by answering earthquaker's question. The forum is there for you to post new threads in for things like that.
For getting trigonometry around together?
almost like those people who join help channels and then query the ops for help
or even worse, some even send channel notices...
or even worse, some even send channel notices...
Help
I've been trying to make a set of code that detects a exact value and resets the variable to value i want. can that be done? its for a annoying dynamove i'm trying to stop from going to far with a zooming effect.
I've been trying to make a set of code that detects a exact value and resets the variable to value i want. can that be done? its for a annoying dynamove i'm trying to stop from going to far with a zooming effect.
You should know very well by now that this is not the idea of this thread.
Next time, create a new thread with what you have so far (no matter how little) instead.
but to answer your question and to get this over with:
But all this are basic operations which you could easially have found yourself in the expression help.
Please don't reply here
Next time, create a new thread with what you have so far (no matter how little) instead.
but to answer your question and to get this over with:
Since you don't want myvar to go to go over a specific value, you could also (or better) use above(a,b) instead of equal(a,b)myvar=if(equal(myvar,value),resetvalue,myvar);
But all this are basic operations which you could easially have found yourself in the expression help.
Please don't reply here
i'm looking for some useful tricks to making menus in avs.
also i'm very much wanting to know how to make global sliders and junk to control certain aspect of my presets.
anything would be nice.
and WoTL this does comply with the idea of this thread.
also i'm very much wanting to know how to make global sliders and junk to control certain aspect of my presets.
anything would be nice.
and WoTL this does comply with the idea of this thread.
This isn't a discussion thread, which means posting code only. (not requests)
See the attached file, some parts may be unoptimized
See the attached file, some parts may be unoptimized
You can attempt to pull the menu out of this one. The slider is alot simpler.
Note: you need globmgr.ape (included).
Note: you need globmgr.ape (included).
*crap removed*
*crap removed*
Converting Movement Equations Polar (r,d) to Parametric (x,y)
I've been working for sometime trying to change polar movement equations into parametric. After looking at a few presents, this is what I came up with:
midx=//x pole goes here;
midy=//y pole goes here;
r=atan2((x-midx),(y-midy));
rx=-cos(r);
ry=sin(r);
dx=sin(r);
dy=cos(r);
d=abs(sqrt(pow(y+midy,2)+pow(x+midx,2)))*2;
midx and midy are the x and y cordiants for the pole (equivilant to the origin in parametric), or the center of the polar equation.
r is the angle counterclockwise from the ray starting at the pole and extending right, and d is the distance from the pole.
rx,dx,ry,dy are the direction of the vector. The first letter is what type of direction (distance or radial) and the second letter is what variable goes under (rx would go under the x=, and dy would go under the y=, etc)
The Vector is comprised of a direction times the distance.
This all may be a bit confusing so here are some sample equations: (asume midx and midy equals 0)
CONVERTING:
r=r+.1;
d=d+.1;
TO
x=x+rx*.1+dx*.1;
y=y+ry*.1+dx*.1;
If you want to multiply a direction by the distance or angle use r or d:
CONVERTING:
r=r+.1/(d+.2);
TO
x=x+rx*.1/(d+.2);
y=y+ry*.1/(d+.2);
I like the equation but the converting process can get kind of annoying. feel free to use any of this and please comment! 🙂
A fun little program:
in the dynamic movements point box:
midx=getkbmouse(1);
midy=getkbmouse(2);
ang=atan2((x-midx),(y-midy));
rx=-cos(ang);
ry=sin(ang);
dx=sin(ang);
dy=cos(ang);
d=abs(sqrt(pow(y+midy,2)+pow(x+midx,2)))*2;
x=x+rx*.05/(d+.2)*sin(d*6)-dx*.05*sin(r*6);
y=y+ry*.05/(d+.2)*sin(d*6)-dy*.05*sin(r*6);
//move your mouse around and have fun!!
I've been working for sometime trying to change polar movement equations into parametric. After looking at a few presents, this is what I came up with:
midx=//x pole goes here;
midy=//y pole goes here;
r=atan2((x-midx),(y-midy));
rx=-cos(r);
ry=sin(r);
dx=sin(r);
dy=cos(r);
d=abs(sqrt(pow(y+midy,2)+pow(x+midx,2)))*2;
midx and midy are the x and y cordiants for the pole (equivilant to the origin in parametric), or the center of the polar equation.
r is the angle counterclockwise from the ray starting at the pole and extending right, and d is the distance from the pole.
rx,dx,ry,dy are the direction of the vector. The first letter is what type of direction (distance or radial) and the second letter is what variable goes under (rx would go under the x=, and dy would go under the y=, etc)
The Vector is comprised of a direction times the distance.
This all may be a bit confusing so here are some sample equations: (asume midx and midy equals 0)
CONVERTING:
r=r+.1;
d=d+.1;
TO
x=x+rx*.1+dx*.1;
y=y+ry*.1+dx*.1;
If you want to multiply a direction by the distance or angle use r or d:
CONVERTING:
r=r+.1/(d+.2);
TO
x=x+rx*.1/(d+.2);
y=y+ry*.1/(d+.2);
I like the equation but the converting process can get kind of annoying. feel free to use any of this and please comment! 🙂
A fun little program:
in the dynamic movements point box:
midx=getkbmouse(1);
midy=getkbmouse(2);
ang=atan2((x-midx),(y-midy));
rx=-cos(ang);
ry=sin(ang);
dx=sin(ang);
dy=cos(ang);
d=abs(sqrt(pow(y+midy,2)+pow(x+midx,2)))*2;
x=x+rx*.05/(d+.2)*sin(d*6)-dx*.05*sin(r*6);
y=y+ry*.05/(d+.2)*sin(d*6)-dy*.05*sin(r*6);
//move your mouse around and have fun!!
framerate-independent movement
there's been some discussion on and off about how to achieve framerate-independence for variables changing over time. with little result. so i finally sat down and calculated it all out. here's how it goes, a quick tutorial about how to make your SSCs, DMs, Triangles and TexerIIs move with the same speed regardless of the fps [frames per second] AVS runs with:
there's three different kinds of changing a variable's value over time that i use frequently. they are of the shape:
so the first thing you need to know is how fast your preset actually runs. you can calculate that by using:
i'll spare you the why's and how's and will just give you the equations. in the first one m is simply multiplied by 'speed' whereas in the other two cases you basically substitute s for a modified 'speed' value [which is the interesting part about this 🙂].
low s -> faster motion.
high s -> slower motion.
dfps is the desired or simulated framerate set by you. it's a constant, maybe 20 to 50. do not use the actual calculated fps!
have fun,
grandchild
_____________
*)
note that this will give you the raw, fluctuating fps, not the number shown in the editor or fullscreen. but this is usually sufficient to get a decent result. 🙂 if you need something smoother, try the third equation from above [without fps-correction, mind you!]
...and if you should need it: the fps is now calculated with 1/speed.
there's been some discussion on and off about how to achieve framerate-independence for variables changing over time. with little result. so i finally sat down and calculated it all out. here's how it goes, a quick tutorial about how to make your SSCs, DMs, Triangles and TexerIIs move with the same speed regardless of the fps [frames per second] AVS runs with:
there's three different kinds of changing a variable's value over time that i use frequently. they are of the shape:
well looks good but these above depend on how fast your preset runs.x = x+m;
//linear movement
y = y*s; // with 0 < s < 1 constant
// y aproaches zero, like e.g. decreasing the effect of a beat-responsive value after a beat.
z = z-(z-zd)*s; ;-or-; z = z*(1-s)+zd*s; // with 0 < s < 1 const.
// both are the same and can be used interchangeably! i use the first one in general.
// here, zd is the 'target value' which is approached after time.
so the first thing you need to know is how fast your preset actually runs. you can calculate that by using:
this gives you the inverted fps*, here called "speed".t = gettime(0); speed = t-old_t; old_t = t;
i'll spare you the why's and how's and will just give you the equations. in the first one m is simply multiplied by 'speed' whereas in the other two cases you basically substitute s for a modified 'speed' value [which is the interesting part about this 🙂].
again s is a constant >0 and <1 which gives the speed of the change:t = gettime(0); speed = t-old_t; old_t = t;
//linear:
x = x+m*speed; // you'll need a bigger m now!
//approaching zero:
speed2 = pow(s,speed*dfps);
y = y*speed2;
//approaching target value [or 'interpolation']:
speed3 = 1-pow(1-s,speed*dfps);
z = z-(z-zd)*speed3;
//or
speed3 = pow(1-s,speed*dfps);
z = z*speed3+zd*(1-speed3);
(1 <- that is a ONE btw. not L)
low s -> faster motion.
high s -> slower motion.
dfps is the desired or simulated framerate set by you. it's a constant, maybe 20 to 50. do not use the actual calculated fps!
have fun,
grandchild
_____________
*)
note that this will give you the raw, fluctuating fps, not the number shown in the editor or fullscreen. but this is usually sufficient to get a decent result. 🙂 if you need something smoother, try the third equation from above [without fps-correction, mind you!]
...and if you should need it: the fps is now calculated with 1/speed.