====== About the script ====== * Purpose : This script will bounce all items randomly around,they will bounce off the screen borders and each other. * Author : F43nd1r * Concept : This script is based on the [[script_llxperiment_boing|boing script]] by TrianguloY * Current Version : 1.1 * Link : https://plus.google.com/105066926163073195690/posts/BMYiNUEss8B (scroll down in the comments) * Video : https://plus.google.com/115366157037831519359/posts/SXcGo6A2gDo ====== Changelog ====== * Version 1.0 (3/5/2014): initial release in wiki * Version 1.1 (18/5/2014): reduced jumps ====== How to use the script ====== * detach all items in a container * set up configuration * run the script in the container ====== Issues and hints ====== * unexpected effects may occur if the items overlap when you start the script * sometimes an item jumps. This happens because the item has no space where it should move to. * If you have set velocity to 1 or bigger, you can cancel the script by opening any app * You'll need a high end phone to run this smoothly with a lot of items. It should work on average phones for up to 5 items. //please report all bugs in the g+ community// ====== Script code ====== var bounciness = 1;//Reduction every tick, between 0 (only one tick) and 1 (always bouncing) [Recommended 0.95] var inVel = 0.02 //initial velocity. set it to 0 for random one [recommended 0.5] var frecuency = 1000;//ticks per second [Recommended 60] var event = LL.getEvent(); var cont = event.getContainer(); var items; items=cont.getItems(); for(var i=items.getLength()-1; i>=0;--i){ var item=items.getAt(i); if(item.getType()=="StopPoint")continue; var ang = Math.random()*2*Math.PI; var invel=inVel; if(invel<=0)invel=Math.random(); invel*=(cont.getHeight()+cont.getWidth())/2; //saving item specific data in the tag var data=new Object(); data.vel = [ Math.cos(ang)*invel , Math.sin(ang)*invel ]; data.size = [ item.getWidth()*item.getScaleX() , item.getHeight()*item.getScaleY() ]; item.setTag(JSON.stringify(data)); } tick(); function tick(){ var changed=false;//value if something changed for(var a=items.getLength()-1; a>=0;--a){ var i=items.getAt(a); if(i.getType()=="StopPoint")continue; var data=JSON.parse(i.getTag()); //continue statement if((Math.abs(data.vel[0])<0.2 && Math.abs( data.vel[1])<0.2)||LL.isPaused()) continue; var changed=true; //Reduction data.vel=[ data.vel[0]*bounciness , data.vel[1]*bounciness ]; var newpos = [ i.getPositionX()+ data.vel[0] , i.getPositionY()+ data.vel[1] ]; //checking all other items after the current for overlap for(var b=a-1; b>=0;--b){ var i2=items.getAt(b); if(i2.getType()=="StopPoint")continue; var data2=JSON.parse(i2.getTag()); var newpos2 = [ i2.getPositionX()+ data2.vel[0] , i2.getPositionY()+ data2.vel[1] ]; var p;//new position of the item with the smaller width/height var p2;//higher width/height var s;//size of the item with the smaller width/height var s2; //higher width/height //horizonatal: if(data.size[0]0){newpos[0]-=2*t; data.vel[0]=-data.vel[0];} //bottom t=(newpos[1]+ data.size[1])-( cont.getPositionY()+cont.getHeight()/cont.getPositionScale() ) ; if(t>0){newpos[1]-=2*t; data.vel[1]=-data.vel[1];} //left t= newpos[0]- cont.getPositionX(); if(t<0){newpos[0]-=2*t; data.vel[0]=-data.vel[0];} //top t= newpos[1]- cont.getPositionY(); if(t<0){newpos[1]-=2*t; data.vel[1]=-data.vel[1];} //set i.setPosition(newpos[0] , newpos[1] ); i.setTag(JSON.stringify(data)); } if(!changed)return; //repeat setTimeout(tick,1000/frecuency); }