Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | pospathos |
Does anyone knows how to write this loop in GDScript:
for (var ix = 0, iy = 0; ix < nx || iy < ny;)?
Code example:
function walk_grid(p0, p1) {
var dx = p1.x-p0.x, dy = p1.y-p0.y;
var nx = Math.abs(dx), ny = Math.abs(dy);
var sign_x = dx > 0? 1 : -1, sign_y = dy > 0? 1 : -1;
var p = new Point(p0.x, p0.y);
var points = [new Point(p.x, p.y)];
for (var ix = 0, iy = 0; ix < nx || iy < ny;) {
if ((0.5+ix) / nx < (0.5+iy) / ny) {
// next step is horizontal
p.x += sign_x;
ix++;
} else {
// next step is vertical
p.y += sign_y;
iy++;
}
points.push(new Point(p.x, p.y));
}
return points;
}
Thanks!
What language is that?
woopdeedoo | 2018-11-05 02:53
Looks like JavaScript to me.
omggomb | 2018-11-05 10:35