User Tools

Site Tools


script_llxperiment_boing

====== About the script ====== * Purpose : This is a script that will move the item from where this script was launched bouncing around the screen. * Author : [[https://plus.google.com/u/1/105066926163073195690|TrianguloY]] * Link: https://plus.google.com/u/1/105066926163073195690/posts/BMYiNUEss8B ====== How to use the script ====== You need to run it from an action involving an item. I recommend the swipe of the item (in any direction. The starting direction is totally random) You can also run it from a container, but it will bounce ALL items in the container, take care. === Modifications === Check [[script_llxperiment_boing_no_overlap|LM13's version]]. Items will also bounce each other! (no overlap) ====== Script code ====== <sxh javascript> var bounciness = 0.95;//Reduction every tick, between 0 (only one tick) and 1 (always bouncing) [Recommended 0.95] var inVel = 0 //initial velocity. set it to 0 for random one [recommended 0.5] var frecuency = 60;//ticks per second [Recommended 60] var event = LL.getEvent(); var cont = event.getContainer(); var clicked = event.getItem(); if(clicked!=null){; run(clicked); }else{ inVel=prompt("This will bounce all items in the container\nAre you sure?\n(velocity,0=random)",inVel) if(inVel==null)return; var items=cont.getItems(); for(var i=items.getLength()-1; i>=0;--i){ var item=items.getAt(i); if(item.getType()!="StopPoint")run(item); } } function run(item){ var ang = Math.random()*2*Math.PI; var invel=inVel; if(invel<=0)invel=Math.random(); invel*=(cont.getHeight()+cont.getWidth())/2; var vel = [ Math.cos(ang)*invel , Math.sin(ang)*invel ]; var size = [ item.getWidth()*item.getScaleX() , item.getHeight()*item.getScaleY() ] tick(item,vel,size); } function tick(item,vel,size){ //exit statement if((Math.abs(vel[0])<1 && Math.abs(vel[1])<1)||LL.isPaused()) return; //Reduction vel=[ vel[0]*bounciness , vel[1]*bounciness ]; var newpos = [ item.getPositionX()+vel[0] , item.getPositionY()+vel[1] ]; var t; //right t=(newpos[0]+size[0])-( cont.getPositionX()+cont.getWidth()/cont.getPositionScale() ) ; if(t>0){newpos[0]-=2*t;vel[0]=-vel[0];} //bottom t=(newpos[1]+size[1])-( cont.getPositionY()+cont.getHeight()/cont.getPositionScale() ) ; if(t>0){newpos[1]-=2*t;vel[1]=-vel[1];} //left t= newpos[0]- cont.getPositionX(); if(t<0){newpos[0]-=2*t;vel[0]=-vel[0];} //top t= newpos[1]- cont.getPositionY(); if(t<0){newpos[1]-=2*t;vel[1]=-vel[1];} //set and repeat item.setPosition(newpos[0] , newpos[1] ); setTimeout(function(){tick(item,vel,size);},1000/frecuency); } </sxh>

script_llxperiment_boing.txt · Last modified: 2014/07/22 14:44 by trianguloy