Skip to content

Commit

Permalink
Don't show trajectory arrows on edge of screen
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmorris committed Apr 6, 2023
1 parent d212eca commit ceb3456
Showing 1 changed file with 29 additions and 24 deletions.
53 changes: 29 additions & 24 deletions lander/trajectory.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,30 +73,35 @@ export const drawTrajectory = (
});

// Draw landing zone angle indicator
const arrowSize = Math.max(
Math.min(lastSegment.projectedYVelocity * 4, 20),
2
);
const arrowLength = Math.max(
Math.min(lastSegment.projectedYVelocity * 30, 60),
5
);
CTX.globalAlpha = 1;
CTX.strokeStyle = "#fff";
CTX.translate(
lastSegment.projectedXPosition,
lastSegment.projectedYPosition
);
CTX.rotate(lastSegment.projectedAngle + Math.PI);
CTX.beginPath();
CTX.moveTo(0, 0);
CTX.lineTo(0, arrowLength);
CTX.lineTo(-arrowSize, arrowLength);
CTX.lineTo(0, arrowLength + arrowSize);
CTX.lineTo(arrowSize, arrowLength);
CTX.lineTo(0, arrowLength);
CTX.closePath();
CTX.stroke();
if (
lastSegment.projectedXPosition > 0 &&
lastSegment.projectedXPosition < canvasWidth
) {
const arrowSize = Math.max(
Math.min(lastSegment.projectedYVelocity * 4, 20),
2
);
const arrowLength = Math.max(
Math.min(lastSegment.projectedYVelocity * 30, 60),
5
);
CTX.globalAlpha = 1;
CTX.strokeStyle = "#fff";
CTX.translate(
lastSegment.projectedXPosition,
lastSegment.projectedYPosition
);
CTX.rotate(lastSegment.projectedAngle + Math.PI);
CTX.beginPath();
CTX.moveTo(0, 0);
CTX.lineTo(0, arrowLength);
CTX.lineTo(-arrowSize, arrowLength);
CTX.lineTo(0, arrowLength + arrowSize);
CTX.lineTo(arrowSize, arrowLength);
CTX.lineTo(0, arrowLength);
CTX.closePath();
CTX.stroke();
}
CTX.restore();
}
};

0 comments on commit ceb3456

Please sign in to comment.