kulanah / latticeSimulator

0 stars 0 forks source link

Adjust canvas size on window resize #27

Open Ensath opened 6 years ago

Ensath commented 6 years ago

Adjusting the canvas size on window resize would be helpful for showing the lattice simulator inside the TEM simulator, since it is shown in a resizable window.

Ensath commented 6 years ago

Here is an example of code that I used to support resizing the diffraction model in the simulator:

// Function from https://github.com/mrdoob/three.js/blob/master/examples/webgl_animation_cloth.html
function onWindowResize() {
    camera.aspect = window.innerWidth / window.innerHeight;
    camera.updateProjectionMatrix();
    renderer.setSize( window.innerWidth, window.innerHeight );
}

window.addEventListener( 'resize', onWindowResize, false );

Note that when I tried using it for the lattice simulator, it would stretch or squash the image, so it was not a perfect solution as is, but it might be helpful.

kulanah commented 6 years ago

Canvas make free resizing extremely difficult, and would require a pretty hefty rewrite of some of the code.

We can force it to stay at a certain aspect ratio given at start of the program, but that's the best case unless we turn this into a fairly sizable project.