I am writing a program to generate some orbital images. I decided to use js because I have a fair amount of experience with it and its fast to write for prototypes. The issue is that when I go to use ctx.putImageData it is rotated by a -45° angle and the image is stretched. This is the actually important code:
genImg(){
let index = 0;
for(let y = 0; y <= 400; y++){
for(let x = 0; x <= 400; x++){
let lx = (x - 200)*this.step;
let ly = (200 - y)*this.step;
this.points.push(this.value(Math.sqrt(Math.pow(lx, 2) + Math.pow(ly, 2)), this.t, Math.atan2(lx,ly))[0]);
}
}
let sclFct = 1000/Math.max(...this.points);
for(let i = 0; i<= 160000; i++){
let val = Math.round(this.points[i]*sclFct);
this.imgDataArr[index] = cmap[val*4]; // R value
this.imgDataArr[index + 1] = cmap[val*4 + 1]; // G value
this.imgDataArr[index + 2] = cmap[val*4 + 2]; // B value
this.imgDataArr[index + 3] = 255; // A value
index += 4;
}
let imgData = new ImageData(this.imgDataArr, 400, 400);
ctx.putImageData(imgData, 0, 0);
}
The Full code is here. Just off the bat I should mention this is all written in a class. The html is just a canvas element in the <main></main> area that is 400px by 400px. The CSS is just to center everything and give the canvas a border. The function this.value(r,t,p) takes the values r(radius), t(theta) and p(phi). Theta is a constant and radius and phi are calculated from (x,y) cords (see line 7 of the prior code).
In the image you can see where there is the diagonal. The black should be in the center with the other colors radiating out. So far I have tried a 45° rotation to the atan2 function, messing with the css and trying to add a rotation, and rotating the ctx element in code (i.e. using ctx.rotate(Math.PI/4)). This all is very strange to me because I have other projects where I have used the same method without issue. Any ideas would be wonderfull!


i <= 160000inclusive, meaning it loops over 160001 color values. This could mean your buffer is "one pixel too wide", causing each row to be shifted left by 1 pixel when "squeezed" into the smaller ImageData, and at scale this looks like a 45 degree skew.< 400(0 - 399 is 400px) rather than<= 400(0-400 is 401px) in the twoforloops creating thepointsarray