# [SOLVED] Line drawing Algorithm

#### Sabnock

##### Member
Looking for a good line drawing algorithm.

I want to be able to per pixel colour a line so i can animate colour along the length of the line which GML does seem to cover

i have looked on line and seen a few options but wanted to get advice on what was best for quick, efficient game use

options i have looked at are:

any help would be appreciated

#### GmlProgrammer

##### Member
You can pass a vertex with two points as a pr_linelist, then you can use any texture you want for your line without rewriting the algorithm.

#### GmlProgrammer

##### Member
Code:
``````///@param x1
///@param y1
///@param x2
///@param y2
///@param color

var xmin = min(argument0,argument2);
var xmax = max(argument0,argument2);
var ymin = min(argument1,argument3);
var ymax = max(argument1,argument3);
var x1 = argument0;
var x2 = argument2;
var y1 = argument1;
var y2 = argument3;
var color = argument4;

var xdist = xmax-xmin;
var ydist = ymax-ymin;

if(xdist == 0 && ydist == 0){
draw_point_color(xmax,ymax,color);
}

if(xdist <= ydist){

for(var yy = ymin; yy <= ymax; yy++){
var xx = round(x2+(x2-x1)*(yy-ymax)/ydist);
if(y1 > y2) xx = round(x1+(x1-x2)*(yy-ymax)/ydist);
draw_point_color(xx,yy,color);
}

}else{

for(var xx = xmin; xx <= xmax; xx++){
var yy = round(y2+(y2-y1)*(xx-xmax)/xdist);
if(x1 > x2) yy = round(y1+(y1-y2)*(xx-xmax)/xdist);
draw_point_color(xx,yy,color);
}

}``````
Also, you can use this simple script I wrote some time ago. You can modify it to add different colors to each point

#### Sabnock

##### Member
You can pass a vertex with two points as a pr_linelist, then you can use any texture you want for your line without rewriting the algorithm.
This looks exactly what i need. I will try it when i get home.

Thank you very much • GmlProgrammer

#### Sabnock

##### Member
You can pass a vertex with two points as a pr_linelist, then you can use any texture you want for your line without rewriting the algorithm.
this works great. thank you again