Can now rotate fully.
This commit is contained in:
parent
0e50c49aad
commit
2c0be8c3bc
Binary file not shown.
Binary file not shown.
27
js/app.js
27
js/app.js
|
@ -1,20 +1,35 @@
|
||||||
var angle_arr = [];
|
var angle_arr = [];
|
||||||
function closest(val){
|
function closest(val){
|
||||||
|
var lessThan0 = val < 0;
|
||||||
|
var geNinety = Math.abs(val)>=90;
|
||||||
|
if(geNinety)
|
||||||
|
if(lessThan0) {
|
||||||
|
val += 90}
|
||||||
|
else
|
||||||
|
val -= 90
|
||||||
|
|
||||||
x= angle_arr.reduce(function(prev, cur) {
|
x= angle_arr.reduce(function(prev, cur) {
|
||||||
return Math.abs(cur.angle - val) < Math.abs(prev.angle - val) ? cur : prev;
|
return Math.abs(cur.angle - Math.abs(val)) < Math.abs(prev.angle - Math.abs(val)) ? cur : prev;
|
||||||
});
|
});
|
||||||
return x;
|
var output = x.angle;
|
||||||
|
if(geNinety)
|
||||||
|
output = x.angle + 90
|
||||||
|
if(lessThan0)
|
||||||
|
output = 0 - output
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return [output,x];
|
||||||
}
|
}
|
||||||
window.onload = function() {
|
window.onload = function() {
|
||||||
fetch('js/angles.json').then((response)=>response.json()).then((json)=>angle_arr=json.angles);
|
fetch('js/angles.json').then((response)=>response.json()).then((json)=>angle_arr=json.angles);
|
||||||
var input = document.getElementById('fileUpload');
|
var input = document.getElementById('fileUpload');
|
||||||
input.addEventListener('change', handleFiles);
|
input.addEventListener('change', handleFiles);
|
||||||
rotation.addEventListener("input", (event) => {
|
rotation.addEventListener("input", (event) => {
|
||||||
var closestAngle = closest(event.target.value);
|
var closestAngle = closest(parseInt(event.target.value));
|
||||||
console.log(closestAngle);
|
event.target.value = closestAngle[0];
|
||||||
event.target.value = closestAngle.angle;
|
|
||||||
angle.textContent = event.target.value;
|
angle.textContent = event.target.value;
|
||||||
tileImg(closestAngle.angle);
|
tileImg(closestAngle[0]);
|
||||||
})
|
})
|
||||||
canvas.width = 700;
|
canvas.width = 700;
|
||||||
canvas.height = 700;
|
canvas.height = 700;
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue