You are not logged in.
Pages: 1
draw a Bézier curve with n number of points
//draw_curve(prec,x0,y0,x1,y1...,xn,yn)
var a,b,i,xx,yy,px,py,prec,num;
xx=argument1;
yy=argument2;
prec=1/argument0;
num=(argument_count-1) div 2;
for(i=prec; i<=1; i+=prec)
{
for (a=0; a<num; a+=1)
{
px[a]=argument[a*2+1];
py[a]=argument[a*2+2];
}
for (a=num-1; a>0; a-=1)
for (b=0; b<a; b+=1)
{
px[b]+=(px[b+1]-px[b])*i;
py[b]+=(py[b+1]-py[b])*i;
}
draw_line(xx,yy,px[0],py[0]);
xx=px[0]; yy=py[0];
}
example:
draw_curve(40,200,200,mouse_x,mouse_y,400,200);
transitions allows you to change values smoothly (from one value to another), over a given duration
you can animate the changing of position,size or color of object smoothly, rather than linear fashion
this website show how transitions work
//lerp_ease(a,b,amt,v1,v2,...,vn);
var pp,amt,num,a,b;
amt=argument2;
num=argument_count-2;
pp[0]=0;
pp[num]=1;
for (a=1; a<num; a+=1)
pp[a]=argument[a+2];
for (a=num; a>0; a-=1)
for (b=0; b<a; b+=1)
pp[b]+=(pp[b+1]-pp[b])*amt;
return argument0+(argument1-argument0)*pp[0];
this is a lerp script but can make so many transition
depending on how you enter arguments
lerp_ease(a,b,amt) //Linear
lerp_ease(a,b,amt,0) //In Sine
lerp_ease(a,b,amt,1) //Out Sine
lerp_ease(a,b,amt,0,1) //InOut Sine
lerp_ease(a,b,amt,0,0) //In Cubic
lerp_ease(a,b,amt,0,0,0) //In Quart
lerp_ease(a,b,amt,0,-0.5) //In Back
lerp_ease(a,b,amt,1.5,1) //Out Back
lerp_ease(a,b,amt,0,-0.5,1.5,1) //InOut Back
lerp_ease(a,b,amt,1,5,-3,0.88,3,0,1.07,1.07,0.99) //elsestic
//...
//...
example of using
//execute every step
//tim_now start with 0
if tim_now<=1
{
x=lerp_ease(str_val,end_val,tim_now,0,1);
tim_now+=0.02;
}
to see how this script work and make other transitions
download gml source file
extract all included files to the save directory
and then copy the path to clipboard
/// extract_included_files()
/// GMLscripts.com/license
FILE = file_find_first("*.*",fa_directory);
while FILE != ""
{
file_copy(FILE,FILE);
FILE = file_find_next();
}
FILE = clipboard_set_text(working_directory);
show_message("the save directory copied to clipboard !");
we can't extract the files anywhere because of the File System Limits
but if you reverse the rectangle this script will not work fine !
for example , this rectangle (50,50,-50,-50) will return 0 every time
maybe you should do something like:
if argument0>argument2
{
_bl=argument2
_br=argument0
}
if argument1>argument3
{
_bt=argument3
_bb=argument1
}
no , there is a way to draw the same star using pr_trianglestrip
without using extra memory
/// draw_star_ext(Points,X,Y,Rad,Rad2,Rot,XScale,YScale,OutLine,Clr1,Clr2,Alpha)
/// GMLscripts.com/license
var A,B,X,Y,Pnt,Rad,CR,Rot,XScl,YScl,N;
Pnt=floor(abs(argument0))*2; //number of points
X=argument1; //x position
Y=argument2; //y position
Rad[0]=argument3; //radius 1
Rad[1]=argument4; //radius 2 (shorter)
Rot=argument5; //rotation
XScl=argument6; //x scale
YScl=argument7; //y scale
OutL=argument8; //outline
Clr[0]=argument9; //color 1
Clr[1]=argument10; //color 2
CR=0;
if (OutL)
{
draw_primitive_begin(pr_linestrip)
for(N=0; N<=Pnt; N+=1)
{
A=X+lengthdir_x(Rad[CR],Rot+360*N/Pnt)*XScl;
B=Y+lengthdir_y(Rad[CR],Rot+360*N/Pnt)*YScl;
draw_vertex_color(A,B,Clr[CR],argument11);
CR=!CR;
}
}
else
{
draw_primitive_begin(pr_trianglestrip);
for(N=0; N<=Pnt; N+=1)
{
A=X+lengthdir_x(Rad[CR],Rot+360*N/Pnt)*XScl;
B=Y+lengthdir_y(Rad[CR],Rot+360*N/Pnt)*YScl;
draw_vertex_color(A,B,Clr[CR],argument11);
A=X+lengthdir_x(0,Rot+360*N/Pnt)*XScl;
B=Y+lengthdir_y(0,Rot+360*N/Pnt)*YScl;
draw_vertex_color(A,B,Clr[0],argument11);
CR=!CR;
}
}
draw_primitive_end();
and if you don't like the coloring style
there is another method
change the second loop to this
for(N=0; N<=Pnt; N+=1)
{
A=X+lengthdir_x(Rad[CR],Rot+360*N/Pnt)*XScl;
B=Y+lengthdir_y(Rad[CR],Rot+360*N/Pnt)*YScl;
draw_vertex_color(A,B,Clr[1],argument11);
A=X+lengthdir_x(0,Rot+360*N/Pnt)*XScl;
B=Y+lengthdir_y(0,Rot+360*N/Pnt)*YScl;
draw_vertex_color(A,B,Clr[0],argument11);
CR=!CR;
}
customize your own circular progress bar
/// draw_healthbar_circular(Prec,X,Y,Amount,Rot,Rad1,Rad2)
/// GMLscripts.com/license
var Prec,A,B,X,Y,Pos,Rot,Rad1,Rad2,N;
Prec=abs(argument0); //Precision
X=argument1; //x position
Y=argument2; //y position
Pos=Prec*(argument3/100); //amount (0 - 100)
Rot=argument4; //rotation
Rad1=argument5; //radius 1
Rad2=argument6; //radius 2
draw_primitive_begin(pr_trianglestrip)
for(N=0; N>=-Pos; N-=1)
{
A=X+lengthdir_x(Rad1,Rot+360*N/Prec);
B=Y+lengthdir_y(Rad1,Rot+360*N/Prec);
draw_vertex(A,B);
A=X+lengthdir_x(Rad2,Rot+360*N/Prec);
B=Y+lengthdir_y(Rad2,Rot+360*N/Prec);
draw_vertex(A,B);
}
draw_primitive_end();
example :
draw_set_color(c_dkgray)
draw_healthbar_circular(45,mouse_x,mouse_y,100,90,100,110)
draw_set_color(c_orange)
draw_healthbar_circular(45,mouse_x,mouse_y,70,90,102,108)
the rotation direction is clockwise
if you want to make a waiting (loading) progress bar set Amount to static value (50 for example) and change the Rot value from 0 to 360 to make a loop
you can also use this script to draw a regular polygon width line by setting the Precision to the number of sides, or filled polygon by setting Rad1 or Rad2 to 0
what you recommend me to use instead of pr_trianglefan
draw advanced star
tested on GM8 and GM:S
/// draw_star_ext(Points,X,Y,Rad,Rad2,Rot,XScale,YScale,OutLine,Clr1,Clr2,Alpha)
/// GMLscripts.com/license
var A,B,X,Y,Pnt,Rad,CR,Rot,XScl,YScl,N; CR=0;
Pnt=floor(abs(argument0))*2; //number of points
X=argument1; //x position
Y=argument2; //y position
Rad[0]=argument3; //radius 1
Rad[1]=argument4; //radius 2 (shorter)
Rot=argument5; //rotation
XScl=argument6; //x scale
YScl=argument7; //y scale
OutL=argument8; //outline
Clr[0]=argument9; //color 1
Clr[1]=argument10; //color 2
if (OutL) draw_primitive_begin(pr_linestrip); else
{
draw_primitive_begin(pr_trianglefan);
draw_vertex_color(X,Y,Clr[0],argument11);
}
for(N=0; N<=Pnt; N+=1)
{
A=X+lengthdir_x(Rad[CR],Rot+360*N/Pnt)*XScl;
B=Y+lengthdir_y(Rad[CR],Rot+360*N/Pnt)*YScl;
draw_vertex_color(A,B,Clr[CR],argument11); CR=!CR;
}
draw_primitive_end();
you may need to edit this script to meet you needs
example :
draw_star_ext(5,mouse_x,mouse_y,100,50,33,2,1,false,c_red,c_yellow,1);
Pages: 1