Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function scrBresenham(x1, y1, x2, y2, grid) {
- var w = x2-x1;
- var h = y2-y1;
- var arr = [];
- var dx1 = 0; var dx2 = 0; var dy1 = 0; var dy2 = 0;
- if (w<0) {dx1 = -1} else if (w > 0) {dx1 = 1};
- if (w<0) {dx2 = -1} else if (w > 0) {dx2 = 1};
- if (h<0) {dy1 = -1} else if (h > 0) {dy1 = 1};
- var longest = abs(w);
- var shortest = abs(h);
- if (!(longest > shortest)) {
- longest = abs(h);
- shortest = abs(w);
- if (h < 0) {dy2 = -1} else if (h > 0) {dy2 = 1}
- dx2 = 0;
- }
- var numerator = longest >> 1;
- for (var i = 0; i <= longest; i++) {
- if (x1 > 0 and y1 > 0 and x1 < ds_grid_width(grid) and y1 < ds_grid_height(grid)) {
- if (ds_grid_get(grid, x1, y1) > 0) {
- array_push(arr, [x1, y1]);
- numerator += shortest;
- if (!(numerator<longest)){
- numerator -= longest;
- x1 += dx1;
- y1 += dy1;
- } else {
- x1 += dx2;
- y1 += dy2;
- }
- }
- }
- }
- return arr;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement