Skip to content

Commit

Permalink
WIP saving
Browse files Browse the repository at this point in the history
  • Loading branch information
JacksonRG committed Jul 20, 2021
1 parent da36153 commit 87d71e6
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 88 deletions.
1 change: 1 addition & 0 deletions src/timeline/js/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -1479,4 +1479,5 @@ App.controller("TimelineCtrl", function ($scope) {
$scope.startImage = "";
};


});
143 changes: 55 additions & 88 deletions src/timeline/js/directives/ruler.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,107 +160,74 @@ App.directive("tlRuler", function ($timeout) {
}
});

/*function drawTimesSeconds() {
ruler = $("#ruler");
ruler.addClass('no_bg')
width = $("body").width();
// Clear all current tick marks
$("#ruler span").remove();
start = Math.max(0, ruler.left - width);
end = ruler.left + (2 * width);
// time = Math.floor(start);
time = Math.floor(start / (scope.project.fps.num / scope.project.fps.den));
while (time <= end) {
console.log("TIME: " + time);
console.log("start: " + start);
console.log("end: " + end);
pos = time * scope.project.pixelsPerSecond;
ruler_mark = $('<span style="left: ' + pos + 'px;">');
ruler_mark.addClass("tick_mark");
time_display = $('<span style="left: ' + pos + 'px;">');
time_display.addClass("ruler_time");
var text_time = secondsToTime(time, scope.project.fps.num, scope.project.fps.den);
time_display[0].innerText = text_time["hour"] + ":" + text_time["min"] + ":" + text_time["sec"];
if (scope.project.scale < 1) {
time_display[0].innerText += ',' + text_time['frame'];
}
ruler.append(ruler_mark);
ruler.append(time_display);
time += 1;
}

}*/
/**
* Given the pixels per second of the project,
* Find a number of frames between each ruler mark,
* such that the tick marks remain at least 50px apart.
*/
function framesPerTick() {
}

/**
*
*/
function drawTimesHighZoom() {
zoomLevels = [
{
// Mark every 10 frames
'zoom': 0.2724177071509648 ,
'mark_every' : 10
},
{
// Mark every 10 frames
'zoom' : 0.1743473325766175,
'mark_every' : 5
},
] ;

ruler = $("#ruler");
ruler.addClass('no_bg')
width = $("body").width();
// Clear all current tick marks
// Delete old tick marks
ruler = $('#ruler');
ruler.addClass('no_bg');
$("#ruler span").remove();

start = Math.max(0, scope.scrollLeft - width);
end = scope.scrollLeft + (2 * width);

console.log("SCALE: " + scope.project.scale);
console.log("start: " + start);
console.log("end: " + end);


let tall = false;
// frame = start;
time = start / (scope.project.fps.num / scope.project.fps.den);
pos = Math.floor(time * scope.pixelsPerSecond);
while (pos < end) {
// for (var i = 1; i < 100; i++) {
ruler_mark = $('<span style="left: ' + pos + 'px;">');
ruler_mark.addClass("tick_mark");
time_display = $('<span style="left: ' + pos + 'px;">');
time_display.addClass("ruler_time");

if (tall) {
ruler_mark.css("height", 14);
tall = false
} else {
tall = true;
startPos = scope.scrollLeft;
endPos = scope.scrollLeft + $("body").width();

// startTime : time[0]; endTime : time[1]
fps = scope.project.fps.num / scope.project.fps.den;
time = [ startPos / scope.pixelsPerSecond, endPos / scope.pixelsPerSecond];
time[0] -= time[0]%1;
time[1] -= time[1]%1 - 1;

t = time[0];
let tPrev;
showTime = true;

framesPerTick = $scope.framesPerTick();
timePerTick = framesPerTick / fps;
while (t <= time[1]){
if (Math.floor(t) != Math.floor(tPrev)) {
// In the case that FPS is not a whole number.
// Every new second, make sure we start ON the second.
t = Math.floor(t);
}

/* Calculate Time */
var text_time = secondsToTime(time, scope.project.fps.num, scope.project.fps.den);
time_display[0].innerText = text_time["hour"] + ":" + text_time["min"] + ":" + text_time["sec"];
if (scope.project.scale < 1) {
time_display[0].innerText += ',' + text_time['frame'];
pos = t * scope.pixelsPerSecond;
tickSpan = $('<span style="left:'+pos+'px;"></span>');
tickSpan.addClass("tick_mark");

if (showTime) {
timeSpan = $('<span style="left:'+pos+'px;"></span>');
timeSpan.addClass("ruler_time");
timeText = secondsToTime(t, scope.project.fps.num, scope.project.fps.den);
timeSpan[0].innerText = timeText['hour'] + ':' +
timeText['min'] + ':' +
timeText['sec'] + ',' +
timeText['frame'];
tickSpan[0].style['height'] = '20px';
showTime = false;
} else {
showTime = true;
}
ruler.append(timeSpan);
ruler.append(tickSpan);

ruler.append(ruler_mark);
ruler.append(time_display);

frame += (scope.project.fps.num / scope.project.fps.den)
time = start / (scope.project.fps.num / scope.project.fps.den);
pos = Math.floor(time * scope.pixelsPerSecond);
tPrev = t;
t += timePerTick;
}
return;
}

drawTimes = () => {
// if (scope.project.scale < 0.340522133938706) {
if (true) {
/*scope.project.scale < 0.340522133938706*/
if (scope.project.scale < 1) {
drawTimesHighZoom();
return;
}
Expand Down
70 changes: 70 additions & 0 deletions src/timeline/js/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,3 +333,73 @@ function moveBoundingBox(scope, previous_x, previous_y, x_offset, y_offset, left

return {"position": snapping_result, "x_offset": x_offset, "y_offset": y_offset};
}

/**
* @param {any number} n
* @returns the list of all primes less than n
*/
function primeNumbersUpTo(n) {
l = [...Array(
Math.floor(
Math.sqrt(n)
)
).keys()];
l = l.slice(2,n); // Discard 0 and 1
l.forEach( i => {
l = l.filter( j => { return j % i == 0 });
});
l.forEach(x=> $scope.primes.add(x));
return l;
}

/**
* @param {integer to factor} n
* @returns the list of prime factors of n
*/
function primeFactorsOf(n) {
n = Math.floor(n);
factors = [];
primes = primeNumbersUpTo(n);
primes.append(n); // in case n is prime.
i = 0;
while (n != 1) {
if(n%primes[i] == 0) {
n = n/primes[i]
factors.append(primes[i]);
} else {
i += 1;
}
}

return factors;
}

/**
* From the pixels per second of the project,
* Find a number of frames between each ruler mark,
* such that the tick marks remain at least 50px apart.
*/
function framesPerTick() {
fps = scope.project.fps.num / scope.project.fps.den;
if (fps % 1 != 0) {
/* Not sure about this. */
}
factors = scope.primeFactorsOf(fps);
dF = 1; // Frames per mark
dT = () => { return dF / fps } // Time per mark
dP = () => { return dT() * scope.pixelsPerSecond }; // Pixels per mark
while (dP() < 35) {
if (dF * 2 > fps && dF < fps) {
dF = fps;
continue;
}
dF *= (factors.shift() || 2);
}
return dF;
}

/**
* Primes are used for factoring.
* Store any that have been found for future use.
*/
$scope.primes = [];

0 comments on commit 87d71e6

Please sign in to comment.