I'm creating a hex based map generator and as part of that I am trying to - on the client side - draw "rivers", lines that travel through the centres of the hexes that the server end calculates have rivers.
Here are the relevant variables (this works it gets values inserted by django from the server end I've tested it it all works fine)
// The optional populators
const rivers = {{ rivers |safe}};
const cities = {{ cities |safe}};
const roads = {{roads |safe}};
// Constants for our angles and scales, starting with scale 5
const a = Math.PI/3;
var r = 5;
And here is the function that draws the rivers
// Function that draws Rivers
function DrawRivers(){
// For each river in the rivers
for (var river of rivers) {
// Set up point tracking
let x_coord = r + river[0][0] * (r + (r * Math.cos(a)));
let y_coord = r + river[0][1] * (r + (r*Math.sin(a)));
if (river[0][0] % 2 == 1) {
y_off = y_coord;
} else { // If it's an even number of tiles in the row it'll be the lower part
y_off = y_coord + r * Math.sin(a);
}
ctx.beginPath();
ctx.lineWidth = r;
ctx.strokeStyle = "#000000";
ctx.moveTo(x_coord, Math.round(y_off))
// For each point in the river
for (var river_hex of river){
let x_coord = r + river[0][0] * (r + (r * Math.cos(a)));
let y_coord = r + river[0][1] * (r + (r*Math.sin(a)));
if (river[0][0] % 2 == 1) {
y_off = y_coord;
} else { // If it's an even number of tiles in the row it'll be the lower part
y_off = y_coord + r * Math.sin(a);
}
ctx.lineTo(x_coord, Math.round(y_off))
}
ctx.closePath();
ctx.stroke();
}
}
However when I run this code the lines do not draw. I've stepped through the code and everything seems like it works; there aren't any points where the code doesn't have the required variables, it's just when the ctx.stroke() command is called it doesn't actually draw the line.
Can someone else see where I've gone wrong? Because I honestly can't...