2023-05-17 07:39:47 +02:00
|
|
|
//CONSTANTS
|
2023-05-16 21:52:42 +02:00
|
|
|
const WIDTH = 1000;
|
|
|
|
const ASPECT_RATIO = 1/2;
|
2023-05-17 08:04:23 +02:00
|
|
|
const MOVE_PIECES = 1/32;
|
2023-05-16 21:52:42 +02:00
|
|
|
|
|
|
|
//CANVAS SHIT
|
|
|
|
let ctx;
|
|
|
|
let canvas;
|
|
|
|
let img; //THE PANORAMA IMAGE
|
|
|
|
|
|
|
|
//CURRENT IMAGE STATE
|
|
|
|
let x1 = WIDTH / 2;
|
2023-05-17 08:04:23 +02:00
|
|
|
let x2; //TODO? Unused
|
2023-05-17 10:43:17 +02:00
|
|
|
let turn = 0; //NEGATIVE MEANS IT IS TURNED LEFT FROM CENTER, POSITIVE IS RIGHT
|
2023-05-16 21:52:42 +02:00
|
|
|
|
2023-05-16 12:29:52 +02:00
|
|
|
function load_panorama()
|
|
|
|
{
|
2023-05-16 21:52:42 +02:00
|
|
|
canvas = document.getElementById('panorama');
|
|
|
|
ctx = canvas.getContext('2d');
|
|
|
|
img = new Image(); //IMAGE
|
2023-05-16 15:15:23 +02:00
|
|
|
|
2023-05-17 08:04:23 +02:00
|
|
|
ctx.canvas.height = WIDTH * ASPECT_RATIO; //TODO! Possible shit happening
|
|
|
|
ctx.canvas.width = WIDTH / 2; //USER WILL SEE A 1/2 OF THE PANORAMA AT THE TIME
|
2023-05-16 15:13:10 +02:00
|
|
|
|
|
|
|
img.onload = function()
|
|
|
|
{
|
2023-05-16 21:52:42 +02:00
|
|
|
x2 = img.width;
|
|
|
|
ctx.drawImage(img, x1, 0, x2, img.height, 0, 0, WIDTH, WIDTH * ASPECT_RATIO); //DRAW A HALF OF img
|
2023-05-16 15:13:10 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
img.src = './res/img/test.jpg';
|
2023-05-16 21:52:42 +02:00
|
|
|
}
|
|
|
|
|
2023-05-17 10:43:17 +02:00
|
|
|
function turn_left()
|
2023-05-16 21:52:42 +02:00
|
|
|
{
|
2023-05-17 10:51:32 +02:00
|
|
|
if (turn < 0 && (Math.abs(turn) - (1/MOVE_PIECES / 2)) >= 0)
|
2023-05-17 10:43:17 +02:00
|
|
|
{
|
2023-05-24 09:45:53 +02:00
|
|
|
//ctx.drawImage(img, x1, 0, img.width * MOVE_PIECES * (Math.abs(turn) - (1/MOVE_PIECES / 2) + 1), img.height, 0 - x1, 0, img.width * MOVE_PIECES * (Math.abs(turn) - (1/MOVE_PIECES / 2) + 1) * WIDTH/img.width, WIDTH * ASPECT_RATIO); //DRAW A HALF OF img //TODO
|
2023-05-17 10:43:17 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-05-17 12:00:46 +02:00
|
|
|
//MOVE AN 8th TO LEFT
|
|
|
|
x1 -= WIDTH * MOVE_PIECES;
|
|
|
|
x2 -= WIDTH * MOVE_PIECES;
|
|
|
|
|
2023-05-17 07:39:47 +02:00
|
|
|
ctx.drawImage(img, x1, 0, img.width - WIDTH * MOVE_PIECES, img.height, 0, 0, WIDTH, WIDTH * ASPECT_RATIO); //DRAW
|
2023-05-17 10:43:17 +02:00
|
|
|
|
|
|
|
turn--;
|
2023-05-17 10:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function turn_right()
|
|
|
|
{
|
|
|
|
if (turn > 0 && (Math.abs(turn) - (1/MOVE_PIECES / 2)) >= 0)
|
|
|
|
{
|
|
|
|
//ctx.drawImage(img, img.width - WIDTH * MOVE_PIECES * (Math.abs(turn) - (1/MOVE_PIECES / 2)), 0, img.width, img.height, 0, 0, WIDTH * MOVE_PIECES * (Math.abs(turn) - (1/MOVE_PIECES / 2)), WIDTH * ASPECT_RATIO); //DRAW RIGHT PART ON THE LEFT SIDE //TODO
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-05-17 12:00:46 +02:00
|
|
|
//MOVE AN 8th TO LEFT
|
|
|
|
x1 += WIDTH * MOVE_PIECES;
|
|
|
|
x2 += WIDTH * MOVE_PIECES;
|
|
|
|
|
2023-05-17 10:51:32 +02:00
|
|
|
ctx.drawImage(img, x1, 0, img.width + WIDTH * MOVE_PIECES, img.height, 0, 0, WIDTH, WIDTH * ASPECT_RATIO); //DRAW
|
|
|
|
|
|
|
|
turn++;
|
2023-05-16 12:29:52 +02:00
|
|
|
}
|