adaptive timing for rev - great TIP!
MisterX
b.xavier at internet.lu
Mon Nov 7 11:25:13 EST 2005
Here's a card script for an image and a fld...
It does a visual effect like we last saw thank to Alex Tweedly
"Image swap algorithm".
What happens in this script is an adaptive but variable
timing for the image swap.
local bestpnumber
constant minTime = 1 -- 1 second it shoul take
constant maxTime = 1.1 -- 1.1 seconds
on mouseUp
if bestpnumber is not a number then put 20 into bestpnumber
get the milliseconds
imageswap the long name of img id 9991013, the long name of fld about,
bestpnumber
put the milliseconds - it into timeTaken
get 1+(100/random(100)+1) -- change only a fraction
if timetaken / 1000 < minTime then multiply bestpnumber by it
else if timetaken / 1000 > maxTime then divide bestpnumber by it
end mouseUp
on imageSwap pObj1, pObj2, pNumber
local r1, r2
local dtlx, dtly, dbrx, dbry
if pnumber is not a number or pnumber < 3 then
put 20 into pNumber
end if
put the rect of pObj1 into r1
put the rect of pObj2 into r2
put (item 1 of r2 - item 1 of r1)/pNumber into dtlx
put (item 2 of r2 - item 2 of r1)/pNumber into dtly
put (item 3 of r2 - item 3 of r1)/pNumber into dbrx
put (item 4 of r2 - item 4 of r1)/pNumber into dbry
repeat with i = 1 to pNumber
if swaplayer <> true then
if i > pnumber / 2 then
set the layer of pObj1 to the layer of pObj2 + 1
put true into swaplayer
end if
end if
set the rect of pObj1 to trunc(item 1 of r1 + i*dtlx), \
trunc(item 2 of r1 + i*dtly), trunc(item 3 of r1 + i*dbrx),
trunc(item 4 of r1 + i*dbry)
set the rect of pObj2 to trunc(item 1 of r2 - i*dtlx), \
trunc(item 2 of r2 - i*dtly), trunc(item 3 of r2 - i*dbrx),
trunc(item 4 of r2 - i*dbry)
end repeat
end imageSwap
More information about the use-livecode
mailing list