GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 2015-11-19 13:22:11

lostdarkwolf
Member
Registered: 2015-11-19
Posts: 23

Vector graphics kit

Gamemaker's vector graphics are limited. This kit helps to ease that issue.

///bezier_get_coord(x0, y0, x1, y1, x2, y2, x3, y3, t);
//
// returns a point within the defined bezier curve.
//
// x0   x of begining bezier vertex, real
// y0   y of begining bezier vertex, real
// x1   x of begining bezier actuator vertex, real
// y1   y of begining bezier actuator vertex, real
// x2   x of ending bezier actuator vertex, real
// y2   y of ending bezier actuator vertex, real
// x3   x of ending bezier vertex, real
// y3   y of ending bezier vertex, real
// t    point to return, real (normal)
//
/// GMLscripts.com/license

var x0, y0, x1, y1, x2, y2, x3, y3, t, cx, cy, bx, by, ax, ay;
x0 = argument[0];
y0 = argument[1];
x1 = argument[2];
y1 = argument[3];
x2 = argument[4];
y2 = argument[5];
x3 = argument[6];
y3 = argument[7];
t = argument[8];

cx = 3*(x1-x0);
cy = 3*(y1-y0);
bx = 3*(x2-x1)-cx;
by = 3*(y2-y1)-cy;
ax = x3-x0-cx-bx;
ay = y3-y0-cy-by;

global.bgc_return_x=ax*power(t,3)+bx*sqr(t)+cx*t+x0;
global.bgc_return_y=ay*power(t,3)+by*sqr(t)+cy*t+y0;
///point_in_polygon(point_x, point_y, polygon_dslist)
//
// returns true if the point in question is within a polygon.
//
// point_x          x coordinate of the point in question, real
// point_y          y coordinate of the point in question, real
// polygon_dslist   a list of lines that forms a polygon, real (ds_list)
//
// the ds_list is a series of x and y coordinates in alternation.
// the coordinates form a line strip.
// there is no need to close the polygon, it is done automatically.
// intersecting polygons are okay.
//
// the format of the polygon is an alternating x and y coordinate system within a ds_list.
//
/// GMLscripts.com/license

var current_direction, start_direction, var_ii, point_quantity, A_A_px, A_A_py, A_A_poly_dsl;
A_px=argument[0];
A_py=argument[1];
A_poly_dsl=argument[2];

current_direction=point_direction(A_px,A_py,ds_list_find_value(A_poly_dsl,0),ds_list_find_value(A_poly_dsl,1));
start_direction=point_direction(A_px,A_py,ds_list_find_value(A_poly_dsl,0),ds_list_find_value(A_poly_dsl,1));
point_quantity=floor(ds_list_size(A_poly_dsl)/2);

// 4503599627370120 is a little less than halfway to the maximum safe integer (9007199254740991)
var_ii=1;
repeat point_quantity-1 {
 current_direction-=angle_difference(current_direction+4503599627370120 mod 360,point_direction(A_px,A_py,ds_list_find_value(A_poly_dsl,var_ii*2),ds_list_find_value(A_poly_dsl,(var_ii*2)+1)));
 var_ii+=1;
}
current_direction-=angle_difference(current_direction+4503599627370120 mod 360,point_direction(A_px,A_py,ds_list_find_value(A_poly_dsl,0),ds_list_find_value(A_poly_dsl,1)));

return round(current_direction/360)!=round(start_direction/360);
///line_in_polygon(polygon_dslist, x1, y1, x2, y2, precision);
//
// returns true if the point in question is within a polygon.
// requires script point_in_polygon.
//
// point_x          x coordinate of the point in question, real
// point_y          y coordinate of the point in question, real
// polygon_dslist   a list of lines that forms a polygon, real (ds_list)
//
// the ds_list is a series of x and y coordinates in alternation.
// the coordinates form a line strip.
// there is no need to close the polygon, it is done automatically.
// intersecting polygons are okay.
//
// the format of the polygon is an alternating x and y coordinate system within a ds_list.
//
/// GMLscripts.com/license

var A_poly_dsl, A_x1, A_y1, A_x2, A_y2, A_prec, travel_dist, travel_direction, return_me, var_ii
A_poly_dsl=argument[0];
A_x1=argument[1];
A_y1=argument[2];
A_x2=argument[3];
A_y2=argument[4];
A_prec=argument[5];

travel_dist=point_distance(A_x1,A_y1,A_x2,A_y2);
travel_direction=point_direction(A_x1,A_y1,A_x2,A_y2);

return_me=1
var_ii=A_prec
while var_ii<travel_dist and return_me=1 {
 return_me=point_in_polygon(A_x1+lengthdir_x(var_ii,travel_direction),A_y1+lengthdir_y(var_ii,travel_direction),A_poly_dsl)
 var_ii+=A_prec;
}

return return_me;
///curve_to_polygon(ds_list,vx1,vy1,vx2,vy2,ax1,ay1,ax2,ay2,width1*,width2*,style*,segments*,tips*,tip_segs*,closed*)
// * not required
//
//  draws a quadratic beizer curve with two widths and various styles
//  
//
//      x1        x1 of beizer curve, real
//      y1        y1 of beizer curve, real
//      x2        x2 of beizer curve, real
//      y2        y2 of beizer curve, real
//      x3        x3 of beizer curve, real
//      y3        y3 of beizer curve, real
//      x4        x4 of beizer curve, real
//      y4        y4 of beizer curve, real
//      style     style of the line, real (integer)
//      width1    width of the beginning of the line, real
//      width2    width of the ending of the line, real
//      segments  segments in line, real (integer)
//      no_tips   set to true to turn off tips, bool
//      tip_segs  segments in the tips, real (integer)
//
//  if the line style is a slit-type line, width2 and no_tips are ignored.
// the format of the polygon is an alternating x and y coordinate system within a ds_list.
//
/// GMLscripts.com/license

/********\
line styles: 
(a "sine bar" is recommended for general use, but a "lerp 
    bar can be useful for lines with easy transitions)
0=tips only (NOT SUPPORTED)
1=sine bar (solid)
2=sine bar (outline)
3=lerp bar (solid)
4=lerp bar (outline)
5=slit (solid)
6=slit (outline)
7=hairline with tips
\********/

var __line_index, __vx1, __vy1, __ax1, __ay1, __ax2, __ay2, __vx2, __vy2, __ii, __segs, __width_index,
    __line_style, __width1, __width2, __xa, __xb, __xc, __ya, __yb, __yc, __dir, __tip_style, __closed;
__ds = argument[0];
__vx1 = argument[1];
__vy1 = argument[2];
__vx2 = argument[3];
__vy2 = argument[4];
__ax1 = argument[5];
__ay1 = argument[6];
__ax2 = argument[7];
__ay2 = argument[8];
__width1 = 1;
if argument_count>9 __width1=argument[9];
__width2 = 1;
if argument_count>10 __width2=argument[10];
__line_style = 1;
if argument_count>11 __line_style=argument[11];
__segs = 256;
if argument_count>12 __segs=argument[12];
if __segs=0 __segs=256
__tips = 1;
if argument_count>13 __tips=argument[13];
__tipsegs=128;
if argument_count>14 __tipsegs=argument[14];
__closed=false;
if argument_count>15 __closed=argument[15];


if __line_style=1 or __line_style=3 or __line_style=5 __line_style+=1; // force outline
if __line_style=7 __tips=false; // tips not supported on hairlines
if __line_style=0 __line_style=2 // style 0 not supported

__width_index=1
__xc = 3*(__ax1-__vx1);
__yc = 3*(__ay1-__vy1);
__xb = 3*(__ax2-__ax1)-__xc;
__yb = 3*(__ay2-__ay1)-__yc;
__xa = __vx2-__vx1-__xc-__xb;
__ya = __vy2-__vy1-__yc-__yb;

__ii=1;
curve_x[0]=__vx1;
curve_y[0]=__vy1;
curve_x[__segs]=__vx2;
curve_y[__segs]=__vy2;

// if vertex 0 is equal to vertex 1, linearize the line.
if __vx1 = __ax1 and __vy1 = __ay1 {
 __ax1=__vx1+lengthdir_x(point_distance(__vx1,__vy1,__vx2,__vy2)/3,point_direction(__vx1,__vy1,__vx2,__vy2))
 __ay1=__vy1+lengthdir_y(point_distance(__vx1,__vy1,__vx2,__vy2)/3,point_direction(__vx1,__vy1,__vx2,__vy2))
}

// if vertex 2 is equal to vertex 3, linearize the line.
if __ax2 = __vx2 and __ay2 = __vy2 {
 __ax2=__vx2+lengthdir_x(point_distance(__vx1,__vy1,__vx2,__vy2)/3,point_direction(__vx2,__vy2,__vx1,__vy1))
 __ay2=__vy2+lengthdir_y(point_distance(__vx1,__vy1,__vx2,__vy2)/3,point_direction(__vx2,__vy2,__vx1,__vy1)) 
}

if __line_style>0 {
//draw_primitive_begin(pr_linestrip)
// LINE 1
repeat __segs+1 { // one side of the outline
  if __line_style=2 __width_index=lerp(__width1,__width2,(-dsin((((1/__segs)*(__ii-1))*180)+90)+1)/2)  // sine bar (outline)
  if __line_style=4 __width_index=lerp(__width1,__width2,max(min((1/(__segs))*(__ii-1),1),0));//lerp bar (outline)
  if __line_style=6 __width_index=dsin(((1/__segs)*(__ii-1))*180)*(__width1/2);//slit (outline)
  if __line_style=7 __width_index=0;  // hairline
  
  __line_index=(1/__segs)*__ii;
  //set line median
  curve_x[__ii] = __xa*power(__line_index,3)+__xb*sqr(__line_index)+__xc*__line_index+__vx1;
  curve_y[__ii] = __ya*power(__line_index,3)+__yb*sqr(__line_index)+__yc*__line_index+__vy1;
  
  if __ii=1 __dir=point_direction(__vx1,__vy1,__ax1,__ay1)+90;
  if __ii=__segs+1 __dir=point_direction(__vx2,__vy2,__ax2,__ay2)-90;
  if __ii!=1 and __ii!=__segs+1 __dir=point_direction(curve_x[__ii-2],curve_y[__ii-2],curve_x[__ii-1],curve_y[__ii-1])+90-(angle_difference(point_direction(curve_x[__ii-2],curve_y[__ii-2],curve_x[__ii-1],curve_y[__ii-1]),point_direction(curve_x[__ii-1],curve_y[__ii-1],curve_x[__ii],curve_y[__ii]))*0.5);

  //draw_vertex(curve_x[__ii-1]+lengthdir_x(__width_index,__dir-180),
  //            curve_y[__ii-1]+lengthdir_y(__width_index,__dir-180));
  ds_list_add(__ds,curve_x[__ii-1]+lengthdir_x(__width_index,__dir-180))
  ds_list_add(__ds,curve_y[__ii-1]+lengthdir_y(__width_index,__dir-180))
  
  __ii++;
}

// TIP (on bars only)
var VAR_is_solid= (__line_style == 0 or __line_style == 1 or __line_style == 3 or __line_style == 7);
if __tips {
if (__line_style = 0 or __line_style = 1 or __line_style = 2 or __line_style = 3 or __line_style = 4) {
  __ii=point_direction(__ax2,__ay2,__vx2,__vy2)-90;
  while __ii<=point_direction(__ax2,__ay2,__vx2,__vy2)+90 {
    //draw_vertex(curve_x[__segs]+lengthdir_x(__width2,__ii),curve_y[__segs]+lengthdir_y(__width2,__ii));
    ds_list_add(__ds,curve_x[__segs]+lengthdir_x(__width2,__ii))
    ds_list_add(__ds,curve_y[__segs]+lengthdir_y(__width2,__ii))
    __ii += 180/__tipsegs;
  }
}
}

// LINE 2
if __line_style=2 or __line_style=4 or __line_style = 6 {//draw the other side of the outline
 __ii=__segs+1;
 repeat __segs+1 {
  if __line_style=2 __width_index=lerp(__width1,__width2,(-dsin((((1/__segs)*(__ii-1))*180)+90)+1)/2)  // sine bar (outline)
  if __line_style=4 __width_index=lerp(__width1,__width2,max(min((1/(__segs))*(__ii-1),1),0));//lerp bar (outline)
  if __line_style=6 __width_index=dsin(((1/__segs)*(__ii-1))*180)*(__width1/2);//slit (outline)
  
  __line_index=(1/__segs)*__ii;
  //set line median
  curve_x[__ii] = __xa*power(__line_index,3)+__xb*sqr(__line_index)+__xc*__line_index+__vx1;
  curve_y[__ii] = __ya*power(__line_index,3)+__yb*sqr(__line_index)+__yc*__line_index+__vy1;
  
  if __ii=1 __dir=point_direction(__vx1,__vy1,__ax1,__ay1)+90;
  if __ii=__segs+1 __dir=point_direction(__vx2,__vy2,__ax2,__ay2)-90;
  if __ii!=1 and __ii!=__segs+1 __dir=point_direction(curve_x[__ii-2],curve_y[__ii-2],curve_x[__ii-1],curve_y[__ii-1])+90-(angle_difference(point_direction(curve_x[__ii-2],curve_y[__ii-2],curve_x[__ii-1],curve_y[__ii-1]),point_direction(curve_x[__ii-1],curve_y[__ii-1],curve_x[__ii],curve_y[__ii]))*0.5);
  
  //draw_vertex(curve_x[__ii-1]+lengthdir_x(__width_index,__dir),
  //            curve_y[__ii-1]+lengthdir_y(__width_index,__dir));
  ds_list_add(__ds,curve_x[__ii-1]+lengthdir_x(__width_index,__dir))
  ds_list_add(__ds,curve_y[__ii-1]+lengthdir_y(__width_index,__dir))
  if __closed!=0 and __ii=1 and __tips=0 {
   //draw_vertex(curve_x[__ii-1]+lengthdir_x(__width_index,__dir-180),
   //            curve_y[__ii-1]+lengthdir_y(__width_index,__dir-180));
   ds_list_add(__ds,curve_x[__ii-1]+lengthdir_x(__width_index,__dir-180))
   ds_list_add(__ds,curve_y[__ii-1]+lengthdir_y(__width_index,__dir-180))
  }
  __ii--;
 }
}
}

// TIP (on bars only)
if __tips {
if (__line_style = 0 or __line_style = 1 or __line_style = 2 or __line_style = 3 or __line_style = 4) {
  __ii=point_direction(__ax1,__ay1,__vx1,__vy1)-90;
  var var_iteration;
  if __closed!=0 var_iteration=__ii<point_direction(__ax1,__ay1,__vx1,__vy1)+90;
  else var_iteration=__ii<point_direction(__ax1,__ay1,__vx1,__vy1)+90-(180/__tipsegs);
  while var_iteration {
    if __closed!=0 var_iteration=__ii<point_direction(__ax1,__ay1,__vx1,__vy1)+90;
    else var_iteration=__ii<point_direction(__ax1,__ay1,__vx1,__vy1)+90-(180/__tipsegs);
    //draw_vertex(curve_x[0]+lengthdir_x(__width1,__ii),curve_y[0]+lengthdir_y(__width1,__ii));
    ds_list_add(__ds,curve_x[0]+lengthdir_x(__width1,__ii))
    ds_list_add(__ds,curve_y[0]+lengthdir_y(__width1,__ii))
    __ii += 180/__tipsegs;
  }
}
}

//draw_primitive_end();

You may have seen the previous version of this script. this is the new and improved version.

///draw_curve(vx1,vy1,vx2,vy2,ax1,ay1,ax2,ay2,width1*,width2*,style*,segments*,tips*,tip_segs*,closed*)
// * not required
//
//  draws a quadratic beizer curve with two widths and various styles
//  
//
//      vx1       x of the first vertex of the beizer curve, real
//      vy1       y of the first vertex of the beizer curve, real
//      vx2       x of the second vertex of the beizer curve, real
//      vy2       y of the second vertex of the beizer curve, real
//      ax1       x of the first vertex's actuator for the beizer curve, real
//      ax2       y of the first vertex's actuator for the beizer curve, real
//      ax2       x of the second vertex's actuator for the beizer curve, real
//      ay2       y of the second vertex's actuator for the beizer curve, real
//      style     style of the line, real (integer)
//      width1    width of the beginning of the line, real
//      width2    width of the ending of the line, real
//      segments  segments in line, real (integer)
//      no_tips   set to true to turn off tips, bool
//      tip_segs  segments in the tips, real (integer)
//
//  if the line style is a slit-type line, width2 and no_tips are ignored.
//
/// GMLscripts.com/license

/********\
line styles: 
(a "sine bar" is recommended for general use, but a "lerp 
    bar can be useful for lines with easy transitions)
0=tips only
1=sine bar (solid)
2=sine bar (outline)
3=lerp bar (solid)
4=lerp bar (outline)
5=slit (solid)
6=slit (outline)
7=hairline with tips
\********/

var __line_index, __vx1, __vy1, __ax1, __ay1, __ax2, __ay2, __vx2, __vy2, __ii, __segs, __width_index,
    __line_style, __width1, __width2, __xa, __xb, __xc, __ya, __yb, __yc, __dir, __tip_style, __closed,
    var_tri_mode, var_do_lines;
__vx1 = argument[0];
__vy1 = argument[1];
__vx2 = argument[2];
__vy2 = argument[3];
__ax1 = argument[4];
__ay1 = argument[5];
__ax2 = argument[6];
__ay2 = argument[7];
__width1 = 1;
if argument_count>8 __width1=argument[8];
__width2 = 1;
if argument_count>9 __width2=argument[9];
__line_style = 1;
if argument_count>10 __line_style=argument[10];
__segs = 256;
if argument_count>11 __segs=argument[11];
if __segs=0 __segs=256
__tips = 1;
if argument_count>12 __tips=argument[12];
__tipsegs=128;
if argument_count>13 __tipsegs=argument[13];
__closed=false;
if argument_count>14 __closed=argument[14];

var_do_lines=1;
var_tri_mode=0;
if __line_style=0 or __line_style=1 or __line_style=3 or __line_style=5 var_tri_mode=1
if __line_style=5 or __line_style=6 or __line_style=7 __tips=false; // tips not supported
if __line_style=0 var_do_lines=0;

__width_index=1
__xc = 3*(__ax1-__vx1);
__yc = 3*(__ay1-__vy1);
__xb = 3*(__ax2-__ax1)-__xc;
__yb = 3*(__ay2-__ay1)-__yc;
__xa = __vx2-__vx1-__xc-__xb;
__ya = __vy2-__vy1-__yc-__yb;

__ii=1;
curve_x[0]=__vx1;
curve_y[0]=__vy1;
curve_x[__segs]=__vx2;
curve_y[__segs]=__vy2;

// if vertex 0 is equal to vertex 1, linearize the line.
if __vx1 = __ax1 and __vy1 = __ay1 {
 __ax1=__vx1+lengthdir_x(point_distance(__vx1,__vy1,__vx2,__vy2)/3,point_direction(__vx1,__vy1,__vx2,__vy2))
 __ay1=__vy1+lengthdir_y(point_distance(__vx1,__vy1,__vx2,__vy2)/3,point_direction(__vx1,__vy1,__vx2,__vy2))
}

// if vertex 2 is equal to vertex 3, linearize the line.
if __ax2 = __vx2 and __ay2 = __vy2 {
 __ax2=__vx2+lengthdir_x(point_distance(__vx1,__vy1,__vx2,__vy2)/3,point_direction(__vx2,__vy2,__vx1,__vy1))
 __ay2=__vy2+lengthdir_y(point_distance(__vx1,__vy1,__vx2,__vy2)/3,point_direction(__vx2,__vy2,__vx1,__vy1)) 
}

if var_tri_mode draw_primitive_begin(pr_trianglestrip);
else draw_primitive_begin(pr_linestrip);
// LINE 1
repeat (__segs+1)*var_do_lines { // one side of the outline
 if __line_style=1 __width_index=lerp(__width1,__width2,(-dsin((((1/__segs)*(__ii-1))*180)+90)+1)/2)  // sine bar (solid)
 if __line_style=2 __width_index=lerp(__width1,__width2,(-dsin((((1/__segs)*(__ii-1))*180)+90)+1)/2)  // sine bar (outline)
 if __line_style=3 __width_index=lerp(__width1,__width2,max(min((1/(__segs))*(__ii-1),1),0));//lerp bar (solid)
 if __line_style=4 __width_index=lerp(__width1,__width2,max(min((1/(__segs))*(__ii-1),1),0));//lerp bar (outline)
 if __line_style=5 __width_index=dsin(((1/__segs)*(__ii-1))*180)*(__width1/2);//slit (solid)
 if __line_style=6 __width_index=dsin(((1/__segs)*(__ii-1))*180)*(__width1/2);//slit (outline)
 if __line_style=7 __width_index=0  // hairline
 
 __line_index=(1/__segs)*__ii;
 //set line median
 curve_x[__ii] = __xa*power(__line_index,3)+__xb*sqr(__line_index)+__xc*__line_index+__vx1;
 curve_y[__ii] = __ya*power(__line_index,3)+__yb*sqr(__line_index)+__yc*__line_index+__vy1;
 
 if __ii=1 __dir=point_direction(__vx1,__vy1,__ax1,__ay1)+90;
 if __ii=__segs+1 __dir=point_direction(__vx2,__vy2,__ax2,__ay2)-90;
 if __ii!=1 and __ii!=__segs+1 __dir=point_direction(curve_x[__ii-2],curve_y[__ii-2],curve_x[__ii-1],curve_y[__ii-1])+90-(angle_difference(point_direction(curve_x[__ii-2],curve_y[__ii-2],curve_x[__ii-1],curve_y[__ii-1]),point_direction(curve_x[__ii-1],curve_y[__ii-1],curve_x[__ii],curve_y[__ii]))*0.5);

 draw_vertex(curve_x[__ii-1]+lengthdir_x(__width_index,__dir-180),
             curve_y[__ii-1]+lengthdir_y(__width_index,__dir-180));
 if var_tri_mode {
  draw_vertex(curve_x[__ii-1]+lengthdir_x(__width_index,__dir),
              curve_y[__ii-1]+lengthdir_y(__width_index,__dir));
 }
 
 __ii++;
}

// TIP (on bars only)
var VAR_is_solid= (__line_style == 0 or __line_style == 1 or __line_style == 3 or __line_style == 7);
if __tips {
 if var_tri_mode {
  draw_primitive_end();
  draw_primitive_begin(pr_trianglefan);
 }
 __ii=point_direction(__ax2,__ay2,__vx2,__vy2)-90;
 if var_tri_mode draw_vertex(curve_x[__segs],curve_y[__segs]);
 while __ii<=point_direction(__ax2,__ay2,__vx2,__vy2)+90 {
  draw_vertex(curve_x[__segs]+lengthdir_x(__width2,__ii),curve_y[__segs]+lengthdir_y(__width2,__ii));
  __ii += 180/__tipsegs;
 }
 if var_tri_mode draw_primitive_end();
}

// LINE 2 (outline only)
if __line_style=2 or __line_style=4 or __line_style = 6 {//draw the other side of the outline
 __ii=__segs+1;
 repeat __segs+1 {
  if __line_style=2 __width_index=lerp(__width1,__width2,(-dsin((((1/__segs)*(__ii-1))*180)+90)+1)/2)  // sine bar (outline)
  if __line_style=4 __width_index=lerp(__width1,__width2,max(min((1/(__segs))*(__ii-1),1),0));//lerp bar (outline)
  if __line_style=6 __width_index=dsin(((1/__segs)*(__ii-1))*180)*(__width1/2);//slit (outline)
  
  __line_index=(1/__segs)*__ii;
  //set line median
  curve_x[__ii] = __xa*power(__line_index,3)+__xb*sqr(__line_index)+__xc*__line_index+__vx1;
  curve_y[__ii] = __ya*power(__line_index,3)+__yb*sqr(__line_index)+__yc*__line_index+__vy1;
  
  if __ii=1 __dir=point_direction(__vx1,__vy1,__ax1,__ay1)+90;
  if __ii=__segs+1 __dir=point_direction(__vx2,__vy2,__ax2,__ay2)-90;
  if __ii!=1 and __ii!=__segs+1 __dir=point_direction(curve_x[__ii-2],curve_y[__ii-2],curve_x[__ii-1],curve_y[__ii-1])+90-(angle_difference(point_direction(curve_x[__ii-2],curve_y[__ii-2],curve_x[__ii-1],curve_y[__ii-1]),point_direction(curve_x[__ii-1],curve_y[__ii-1],curve_x[__ii],curve_y[__ii]))*0.5);
  
  draw_vertex(curve_x[__ii-1]+lengthdir_x(__width_index,__dir),
              curve_y[__ii-1]+lengthdir_y(__width_index,__dir));
  if __ii=1 and __tips=0 {
   draw_vertex(curve_x[__ii-1]+lengthdir_x(__width_index,__dir-180),
               curve_y[__ii-1]+lengthdir_y(__width_index,__dir-180));
  }
  __ii--;
 }
}

// TIP (on bars only)
if __tips {
 if var_tri_mode {
  draw_primitive_end();
  draw_primitive_begin(pr_trianglefan);
 }
 __ii=point_direction(__ax1,__ay1,__vx1,__vy1)-90;
 if var_tri_mode draw_vertex(curve_x[0],curve_y[0]);
 while __ii<=point_direction(__ax1,__ay1,__vx1,__vy1)+90 {
  draw_vertex(curve_x[0]+lengthdir_x(__width1,__ii),curve_y[0]+lengthdir_y(__width1,__ii));
  __ii += 180/__tipsegs;
 }
 if var_tri_mode draw_primitive_end();
}

draw_primitive_end();
///draw_quad_beizer(vx1, vy1, vx2, vy2, ax1, ay1, ax2, ay2, segs)
//
// draws a quadratic bezier curve
// requires script bezier_get_coord.
//
// vx1    x of the begining vertex of the bezier curve, real
// vy1    y of the begining vertex of the bezier curve, real
// vx2    x of the ending vertex of the bezier curve, real
// vy2    y of the ending vertex of the bezier curve, real
// ax1    x of the begining actuator vertex of the bezier curve, real
// ay1    y of the begining actuator vertex of the bezier curve, real
// ax2    x of the begining actuator vertex of the bezier curve, real
// ay2    y of the begining actuator vertex of the bezier curve, real
// segs   number of segments within the bezier curve, real (integer)
//
/// GMLscripts.com/license

vx1=argument[0];
vy1=argument[1];
vx2=argument[2];
vy2=argument[3];
ax1=argument[4];
ay1=argument[5];
ax2=argument[6];
ay2=argument[7];
segs=argument[8];

var var_progress=0;
bezier_get_coord(vx1,vy1,ax1,ay1,ax2,ay2,vx2,vy2,var_progress)
repeat segs {
 var_sx=global.bgc_return_x;
 var_sy=global.bgc_return_y;
 var_progress+=1/segs
 bezier_get_coord(vx1,vy1,ax1,ay1,ax2,ay2,vx2,vy2,var_progress)
 draw_line(var_sx,var_sy,global.bgc_return_x,global.bgc_return_y);
}
///draw_polygon(polygon_dsl, validation_precision*)
// * optional argument
//
// Draws a polygon using the ear-clipping technique.
// Requires scripts line_in_polygon and point_in_polygon.
//
// polygon_dsl
// validation_precision
//
// the format of the polygon is an alternating x and y coordinate system within a ds_list.
//
/// GMLscripts.com/license

var A_polygon_dsl, A_validation_precision, var_drawn_triangles, pre_vertex, pre_x, pre_y,
    work_vertex, pro_vertex, var_vertex_count, pro_x, pro_y;
A_polygon_dsl=argument[0]
A_validation_precision=1;
if argument_count>1 A_validation_precision=argument[1];

var_drawn_triangles=0
pre_vertex=0
pre_x=ds_list_find_value(A_polygon_dsl,0);
pre_y=ds_list_find_value(A_polygon_dsl,1);
work_vertex=0
pro_vertex=1
var_vertex_count=ds_list_size(A_polygon_dsl)/2;

// repeat until all triangles are are drawn. (all triangles are vertex count minus two.)
draw_primitive_begin(pr_trianglelist);
while (var_drawn_triangles<var_vertex_count-2) {
 // advance only the working vertex, and the proceeding vertex
 work_vertex=(work_vertex+1) mod var_vertex_count;
 pro_vertex=(pro_vertex+1) mod var_vertex_count;
 
 // if a line from the proceeding vertex, to the preceeding vertex, is within the polygon, make a triangle.
 pro_x=ds_list_find_value(A_polygon_dsl,pro_vertex*2)
 pro_y=ds_list_find_value(A_polygon_dsl,(pro_vertex*2)+1)
 if line_in_polygon(A_polygon_dsl, pre_x, pre_y, pro_x, pro_y, A_validation_precision) {
  var_drawn_triangles+=1;
  draw_vertex(pre_x,pre_y)
  draw_vertex(pro_x,pro_y)
  draw_vertex(ds_list_find_value(A_polygon_dsl,work_vertex*2),ds_list_find_value(A_polygon_dsl,(work_vertex*2)+1))
 }
 // else, set the preceeding vertex to the working vertex
 else {
  pre_vertex=work_vertex;
  pre_x=ds_list_find_value(A_polygon_dsl,pre_vertex*2)
  pre_y=ds_list_find_value(A_polygon_dsl,(pre_vertex*2)+1)
 }
}
draw_primitive_end();

Last edited by lostdarkwolf (2019-07-23 12:31:25)

Offline

#2 2019-07-23 12:09:54

lostdarkwolf
Member
Registered: 2015-11-19
Posts: 23

Re: Vector graphics kit

bump. (Six new scripts added to main post)

Offline

Board footer

Powered by FluxBB