This is something I had since long time ago (almost 3 months now)
This is something I had since long time ago (almost 3 months now)
I never published it because I didn’t like how it is done (the code is a bit messy) but with some little changes I made recently I think it’s time to do so.
This script moves the items of the desktop based on Lagrange interpolation.
You specify data of an item in some pages and it will move smoothly from one to another.
It is made as efficient as possible. No saved data is not counted, and even with so much pages saved it should be unnoticeable. (Of course this depends on the device)
To use it only set it in the position change event of the desired container. Then save the data of each item (one by one, sorry) as seen in the video.
]]>
< ![CDATA[
var extrapolate=false;//set this to true to extrapolate
//clases
LL.bindClass(“android.app.AlertDialog”);
LL.bindClass(“android.content.DialogInterface”);
//vars
var event=LL.getEvent();
var item=event.getItem();
var cont=event.getContainer();
var source=event.getSource();
//the list of parameters
var parameters = [“Position X”,”Position Y”,”Rotation”,”Scale X”,”Scale Y”,”Alpha”,”Width”,”Height”];
//vars related to the interpolation data
var data=JSON.parse(cont.getTag(“intpol”))||{};
var d;
var page;
var flags=[];
if(source==”C_POSITION_CHANGED”){
//interpolate
apply();
}else if(item!=null){
//apply settings for the item
//create the object that will contain the data
d=(data[item.getId()])||{flags:[],lagrange:[],pages:[]};
while(d.flags.length
while(d.pages.length
//the list of properties
for(var t in d.flags)flags[t]=d.flags[t];
choose();
}else{
//no item
alert(“run the script from an item”);
//prompt(“”,cont.getTag(“intpol”));//for debug
}
function choose(){
//shows the dialogs
//asks for the page (selected: current)
var w=cont.getWidth();
var x=cont.getPositionX();
var b=cont.getBoundingBox();
page=w*LL.pickNumericValue(“save for which page? (horizontally, 0 is the main page)”, Math.round(x/w), “FLOAT”, Math.floor(b.getLeft()/w)-1, Math.ceil(b.getRight()/w), 1, “page”);
if(page==null)return;
//parameters
var builder=new AlertDialog.Builder(LL.getContext());
builder.setTitle(“Choose parameters to save/remove”);
builder.setMultiChoiceItems(parameters,flags,new DialogInterface.OnMultiChoiceClickListener(){onClick:function(dialog,which,checked){flags[which]=checked;}});
builder.setNegativeButton(“Cancel”,null);
builder.setPositiveButton(“Save”,new DialogInterface.OnClickListener(){onClick:save});
builder.setNeutralButton(“Remove”,new DialogInterface.OnClickListener(){onClick:remove});
builder.create().show();
}
function save(){
//save the data of the selected parameters
if(flags[0])d.pages[0][page]=item.getPositionX();
if(flags[1])d.pages[1][page]=item.getPositionY();
if(flags[2])d.pages[2][page]=item.getRotation();
if(flags[3])d.pages[3][page]=item.getScaleX();
if(flags[4])d.pages[4][page]=item.getScaleY();
if(flags[5])d.pages[5][page]=item.getProperties().getInteger(“i.alpha”);
if(flags[6])d.pages[6][page]=item.getWidth();
if(flags[7])d.pages[7][page]=item.getHeight();
update();
}
function update(){
//create the polynomial for each animated parameter
for(var t=0;t
difdiv(d.pages[t],Object.keys(d.pages[t]).sort(function(a,b){return parseInt(a)-parseInt(b);}),t);
}
//save the data
data[item.getId()]=d;
cont.setTag(“intpol”,JSON.stringify(data));
}
function remove(){
//removed the data of the selected parameters
for(var t=0;t
if(flags[t]) delete d.pages[t][page];
}
update();
}
function apply(){
//sets the data when moving the desktop
var ids=Object.keys(data);
for(var t=0;t
var item=LL.getItemById(ids[t]);
if(item==null){
//if a saved item is not found, removes the data of that item
delete data[ids[t]];
cont.setTag(“intpol”,JSON.stringify(data));
continue;
}
//apply the interpolation
d=data[ids[t]];
if(d.flags[6]||d.flags[7])item.setSize(d.flags[6]?intpol(6):item.getWidth(),d.flags[7]?intpol(7):item.getHeight());
if(d.flags[2])item.setRotation(intpol(2));
if(d.flags[3]||d.flags[4])item.setScale(d.flags[3]?intpol(3):item.getScaleX(),d.flags[4]?intpol(4):item.getScaleY());
if(d.flags[0]||d.flags[1])item.setPosition(d.flags[0]?intpol(0):item.getPositionX(),d.flags[1]?intpol(1):item.getPositionY());
if(d.flags[5])item.getProperties().edit().setInteger(“i.alpha”,intpol(5,0,255)).commit();
}
}
function intpol(prop,min,max){
//fixed function: based of the saved polynomial returns the value
var c=cont.getPositionX();
var index=d.lagrange[prop];
var n=index[0].length-1;
if(!extrapolate){
if(c>index[1][n]) return d.pages[prop][index[1][n]];
if(c
}
var out=index[0][n];
for(var t=n-1;t>=0;–t){
out=index[0][t]+(c-index[1][t])*out;
}
if(min!=null&&out
if(max!=null&&out>max)return max;
return out;
}
function difdiv(values,nodes,prop){
//fixed function: calculates the data of the interpolation polynomial based on the saved data
var y=[[]];
var n=nodes.length;
if(n< =0){
delete d.lagrange[prop];
d.flags[prop]=false;
}else{
d.flags[prop]=true;
}
for(var t=0;t
y[t]=[];
y[t][0]=values[nodes[t]];
}
for(var k=1;k
:{
y[i][k]=(y[i+1][k-1]-y[i][k-1])/(nodes[i+k]-nodes[i]);
}
if(d.lagrange[prop]==null)d.lagrange[prop]=[];
d.lagrange[prop][0]=y[0];
d.lagrange[prop][1]=nodes;
}
/*
data:{
flags:[,] //will animate or not
lagrange:[property]:{
[0]: d of the polynomial
[1]: nodes
}
pages:[property]{
[page] value of that property at the current page
}
}
}
*/
]]>
< ![CDATA[
Absolutely stunning.
]]>
< ![CDATA[
Amazing. So cool.
]]>
< ![CDATA[
You never stop to amaze me. Your work is really showing of LLX’s potential, if somebody has some scripting skills
]]>
< ![CDATA[
Wow… is stupend… Congratulation for your Big idea…
]]>
< ![CDATA[
I want to say unbelievable but if TrianguloY name is associated to it, there is no cause to doubt.
]]>
< ![CDATA[
Can’t wait to use this on something! Great work
]]>
< ![CDATA[
Fun use of mathematics!
]]>
< ![CDATA[
very cool
]]>
< ![CDATA[
TrianguloY I have a suggestion if it’s no bother. Can you include a way remove an item when you set the alpha property to 0 similar to your dim background script?
]]>
< ![CDATA[
Sergio Azar not sure which script are you talking, but if the item is removed…it will be deleted and won’t go back. I mean it will be a ‘one-slide’ item. Why (and what) do you want exactly?
]]>
< ![CDATA[
Apologies for bumping an older post, but I can’t seem to get this working with the latest version of LLx. I’ve followed all of the steps in the video. Is this method outdated and incompatible with the current version of LLx?
]]>
< ![CDATA[
Technically it should work but I’ll check it.
]]>
< ![CDATA[
Thanks. I’d love to have a home screen built around interpolation.
]]>
< ![CDATA[
I tested it and works.
Are you sure you:
Set the script on the position change event?
Detached the items?
Can scroll the desktop?
]]>
< ![CDATA[
I’ve detached the items and can scroll the desktop, but how exactly do I set the script on position change event?
]]>
< ![CDATA[
Desktop setting – events & action – position change event – run a script – choose the interpolation script, done.
]]>
< ![CDATA[
That’s it! I think I finally understand how this works now. Thank you very much.
]]>
< ![CDATA[
I can’t seem to get this script to work while scrolling vertical. Is there something I need to change?
]]>
< ![CDATA[
It’s strange I didn’t allow that with a parameter. Probably due to the fact this script was made more than two years ago. Does it still works for you? (I mean, no errors when running?)
To change the input from a horizontal scroll to a vertical one you need to change one line. Search for the line that says:
>var c=cont.getPositionX();
that is just under the intpol function definition (third chunk from the bottom) and change it to
>var c=cont.getPositionY();
]]>
< ![CDATA[
TrianguloY yep works great. Thanks again
]]>