Cool Script animation

MisterX b.xavier at internet.lu
Sun Feb 20 08:50:49 EST 2005


Alejandro,

 Here's the fix! Hope you like it!

 Next script is even better and you could combine the color mixer with this
one for some cool effects ;)

cheers
Xavier

--

local xspeed, yspeed
local oldx, oldy
local rightedge,leftedge
local topedge, bottomedge
local gravity, fxdrag, bounce
local inited


-- easing
local k=.2
local damp=.9
local vx=0,vy=0
local ax=0.1,ay=0

 
on mousedown
   
  if inited is not true then
    initme
  end if
  put 15 into xspeed
  put 15 into yspeed
  
  put the width of me into mW
  put the height of me into mH
  put mW div 2 into mW2
  put mH div 2 into mH2
  put the mouseh - left of me into xoff
  put the mousev - top  of me into yoff
  
  put the rect of this cd into limits
  lock messages
  
  repeat while the mouse is down
     
    put left of me + xoff into midx
    put top  of me + yoff into midy
    
    put the mouseh into nux
    put the mousev into nuy
     
    -- limit if out of 3dpane
     
    get the left of me
    add (nux - midx) / xspeed to it
    if it <= item 1 of limits
    then get item 1 of limits
    else if it + mW >= item 3 of limits
    then get item 3 of limits - mW
    set the left of me to it
    
    get the top of me
    add (nuy - midy) / yspeed to it
    if it <= item 2 of limits
    then get item 2 of limits
    else if it + mH >= item 4 of limits
    then get item 4 of limits - mH
    set the top of me to it
     
     
  end repeat
  put 6 into xspeed
  put 6 into yspeed
 idlemove
end mousedown


on initme
  --put the left of graphic 1 into oldx
  --put the top  of graphic 1 into oldy
 
  put random(40)-30 into xspeed
  put random(40)-30 into yspeed
 
  put 0 into leftedge
  put 0 into topedge
  put width of this cd into rightedge
  put the height of this cd into bottomedge
 
  put 2    into gravity
  put 0.97 into fxdrag
  put 0.9  into bounce
  put true into inited 
  domove 1
end initme

on idlemove
  domove 1
  get me
  if the shiftkey is up then
    send "idlemove" to me in 160 milliseconds
  end if
end idlemove

on domove objnum
  local x, y 
   put the left of graphic objnum into x
    add xspeed to x
    set the left of graphic objnum to x
 
    if (x + the width of graphic objnum > rightedge) then
      put rightedge - the width of graphic objnum into x
      set the left of graphic objnum to x
      put -xspeed * bounce into xspeed
    end if
 
    if (the left of graphic objnum - the width of graphic objnum < leftedge)
then
      set the left of graphic objnum to leftedge + the width of graphic
objnum
      put -xspeed * bounce into xspeed
    end if
 
    put the top of graphic objnum into y
    add yspeed to y
    set the top of graphic objnum to y
 
    if (the top of graphic objnum + the height of graphic objnum >
bottomedge) then
      set the top of graphic objnum to bottomedge - the height of graphic
objnum 
      put -yspeed * bounce into yspeed
    end if
 
    if (the top of graphic objnum - the height of graphic objnum < topedge)
then
      set the top of graphic objnum to topedge + the height of graphic
objnum 
      put -yspeed * bounce into yspeed
    end if
 
    put yspeed * fxdrag + gravity into yspeed
    put xspeed * fxdrag into xspeed
 
end domove



More information about the use-livecode mailing list