Skip to content

Commit

Permalink
animate fold angle
Browse files Browse the repository at this point in the history
  • Loading branch information
amandaghassaei committed Jul 3, 2017
1 parent 6a338f8 commit 5f9f5d7
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 16 deletions.
7 changes: 7 additions & 0 deletions css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -481,4 +481,11 @@ a.seeMore.closed>.fui-triangle-down{
#animationSetupModal p, #animationSetupModal ul, #animationSetupModal div.btns{
text-align: center;
padding: 0;
}
.warning{
color: #f1970f;
}

.red{
color:red!important;
}
20 changes: 19 additions & 1 deletion js/controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,10 @@ function initControls(globals){
$("#recordStatus").show();
globals.shouldScaleCanvas = false;
globals.capturer.start();
if (globals.videoAnimator.isValid()) {
globals.shouldAnimateFoldPercent = true;
globals.videoAnimator.compile();
}
});
setLink("#doGifRecord", function(){
globals.capturerFrames = 0;
Expand All @@ -290,6 +294,10 @@ function initControls(globals){
$("#recordStatus").show();
globals.shouldScaleCanvas = false;
globals.capturer.start();
if (globals.videoAnimator.isValid()) {
globals.shouldAnimateFoldPercent = true;
globals.videoAnimator.compile();
}
});

setLink("#stopRecord", function(){
Expand All @@ -299,6 +307,7 @@ function initControls(globals){
globals.capturer.save();
globals.capturer = null;
globals.shouldScaleCanvas = false;
globals.shouldAnimateFoldPercent = false;
globals.threeView.onWindowResize();
$("#recordStatus").hide();
});
Expand Down Expand Up @@ -425,6 +434,14 @@ function initControls(globals){
$('#creasePercent>input').val(val);
}, -100, 100);

function updateCreasePercent(){
var val = globals.creasePercent*100;
creasePercentSlider.slider('value', val);
creasePercentNavSlider.slider('value', val);
$('#currentFoldPercent').val(val);
$('#creasePercent>input').val(val);
}

function setDeltaT(val){
$("#deltaT").html(val.toFixed(4));
}
Expand Down Expand Up @@ -774,7 +791,8 @@ function initControls(globals){
}

return {
setDeltaT: setDeltaT
setDeltaT: setDeltaT,
updateCreasePercent: updateCreasePercent
}
}

7 changes: 7 additions & 0 deletions js/dynamic/dynamicSolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ function initDynamicSolver(globals){

function solve(_numSteps){

if (globals.shouldAnimateFoldPercent){
globals.creasePercent = globals.videoAnimator.nextFoldAngle(0);
globals.controls.updateCreasePercent();
setCreasePercent(globals.creasePercent);
globals.shouldChangeCreasePercent = true;
}

if (globals.forceHasChanged) {
updateExternalForces();
globals.forceHasChanged = false;
Expand Down
3 changes: 2 additions & 1 deletion js/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ function initGlobals(){
capturerScale: 1,
capturerFrames: 0,
shouldScaleCanvas: false,
isGif: false
isGif: false,
shouldAnimateFoldPercent: false
};

function setCreasePercent(percent){
Expand Down
74 changes: 60 additions & 14 deletions js/videoAnimator.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,41 @@ function initVideoAnimator(globals){

var foldAngleSequence = [];

function clear(){
foldAngleSequence = [];
render();
function compile(){
var lastAngle = globals.creasePercent*100;
var t = 0;
for (var i=0;i<foldAngleSequence.length;i++){
var item = foldAngleSequence[i];
item.t = t;
item.from = lastAngle;
if (item.type == "delay") item.to = lastAngle;
lastAngle = item.to;
t += item.dur;
}
}

function nextFoldAngle(stepNum){
var fps = globals.currentFPS;
var frame = globals.capturerFrames + stepNum/globals.numSteps;
var t = frame/fps;
var item = getItemForT(t);
if (item === null) {
globals.shouldAnimateFoldPercent = false;
return globals.creasePercent;
}
if (item.dur == 0) return item.to/100;
t -= item.t;
t /= item.dur;
var angle = item.from*(1-t) + item.to*t;
return angle/100;
}

function getItemForT(t){
for (var i=0;i<foldAngleSequence.length;i++){
var item = foldAngleSequence[i];
if (t <= item.t + item.dur) return item;
}
return null;
}

function addItem(){
Expand All @@ -23,26 +55,37 @@ function initVideoAnimator(globals){
}

function addDelay(){
foldAngleSequence.push({type:"delay", dur:null});
foldAngleSequence.push({
type:"delay",
dur:null,
from: null,
to: null
});
render();
}

function setAnimationStatus(){
if (foldAngleSequence.length == 0) {
$("#foldPercentAnimationStatus").html("no animation configured");
return;
}
var complete = true;
function isValid(){
if (foldAngleSequence.length == 0) return false;
for (var i=0;i<foldAngleSequence.length;i++){
var item = foldAngleSequence[i];
if (item.type == "delay" && item.dur !== null) continue;
if (item.type == "animation" && item.dur !== null && item.to != null) continue;
complete = false;
break;
return false
}
return true;
}

function setAnimationStatus(){
if (foldAngleSequence.length == 0) {
$("#foldPercentAnimationStatus").removeClass("warning");
$("#foldPercentAnimationStatus").html("no animation configured");
return;
}
if (complete) {
if (isValid()) {
$("#foldPercentAnimationStatus").removeClass("warning");
$("#foldPercentAnimationStatus").html("animation configured");
} else {
$("#foldPercentAnimationStatus").addClass("warning");
$("#foldPercentAnimationStatus").html("incomplete config, will be ignored");
}
}
Expand Down Expand Up @@ -124,6 +167,9 @@ function initVideoAnimator(globals){

return {
addItem: addItem,
addDelay: addDelay
addDelay: addDelay,
isValid: isValid,
compile: compile,
nextFoldAngle: nextFoldAngle
}
}

0 comments on commit 5f9f5d7

Please sign in to comment.