Help with image effect

MisterX b.xavier at internet.lu
Mon Oct 24 14:50:59 EDT 2005


Alex

Here's the new script I made - note that now it's TAOO style ;)
It applies to any control's rect... And it swaps layers at some
point.
The third parameter is a bit improved and the layer switch couldn't
be smarter - no detection needed however it will switch one image's 
layer above anything else... That can be changed correctly with a 
bit more scripting...

What's TAOO about this handler? It handles any occasion! It was
improved, it's shared among the community for more ideas!

Results of tests with changing pNumber below because I noticed 
a big difference between a topnotch gaming PC and a portable that
I wasn't expecting...

on mouseUp
  imageswap the long name of img 1, the long name of img 2,fld 1
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 img 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 img 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 

Now, the info regarding optimizing this function. 

You cant! But you can get close...

Other than changing the pNumber or inducing timed updated (do a visual
change every x milliseconds). This gives a smooth timed transition based on
a time frame, irrelevant of CPU speed. Alas this doesn't work for slower
than slow cpus and may cause choppiness or lagged-draws.

Next, and entirely to my surprise, the gaming station compared to the
portable was not showing any "progress animation" until I set the pnumber to
240 otherwise, it was too fast!!! And that's with the correction for dtlx
and the other dtAB {where A=l|r, B=x|y}

Now that's 240 steps compared to 20 steps to make an animation smooth from
start to finish (in about a second) in my ultra-cooled (or it flips the
switch) "PC-workstation"! I spent 70EUs to cool this CPU 30 centigrades
below shutdown temperature...

Now, before I explain the next step, I must say that im not a gaming fan
anymore but I know LOTs about it because I always seek that virtual nirvana
which came at each release of DOOM, Quake 3, Doom 4 (which was awesome
graphics and physics wise but apparently Quake 4 sucks), and the most
virtual gut twisting Descent and Descent II games. Total 3D!

And swapping images is getting there because it gives you that perspective
animation!!! Castle Wolfenstein technology - before DOOM! 

But where this really took a whole new dimension is not with GTR
(simbin.com) game but Simbin's new GTL Legends which really puts GTR down a
category - and this is where I think PC's personal computing power put you
into the seat of Descent or GTL like it's real - OR NOT!!! But without a
million FPS (Frames per second) these games don’t do justice to their
capabilities on any PC, they can't draw fast enough - imagine RunRev without
3D or direct access to the graphic power in your hardware now... Yet my GTR
optimized PC is not enough for GTL!!! Now, lets explain how a 100+FPS Quake
3 or 70FPS GTR graphic station can do in rev! I couldn't animate more than
20 polygons smoothly in a moire on my previous PC maybe, I can do maybe 50
smoothly now with the new hardware (to be tested tonite!) yet this portable
goes faster!

Now I subjected my gaming station which did smoothly in the image swap even
at pnumber=20... The answer is simple in terms of gaming performance: FPS!
The more FPS = smoother animation. Less FPS = performance lag OR skipped
frames. And in the case of the portable, it's what I'd like to thing
happens. Maybe someone can correct me with that... im not confident in the
whole answer for the portable - the video card is definitely not faster than
my gaming station... 

BUT after a point where cpu performance = FPS (hopefully fast), the cpu
draws faster than the video card - unlike video games, this isn't synched
with the video refresh draw cycles in RunRev. So you have to induce the draw
at the number of FPS you want... Examples: Old Disney cartoons=12 FPS, NTSC
video = 25.x FPS, PAL(/secam?)=24.xFPS, computer's fastest redraw = the
number of hertz of your video card/monitor redraw mode... faster CPU draw =
flicker... slower draw = laag...

so how do you optimise this? You play the animation once to get the
cpu/refresh speed at a number of pnumber draws - which is equal to a number
of milliseconds... so the rest is drawing only within the number of cycles
you need to. So for 24 fps, you send a draw or wait for the number of
milliseconds to draw or (if millisecond mod (fps+-tolerance) is not your
redraw speed, then DRAW... 

Major tip: Don’t check for x more milliseconds after last redraw to draw,
check to the "time" to draw... This is the milliseconds mod drawtimeinFPM
(frames per ms).

Putting this into practice is the next step... which I leave as exercise...
for the cunning scripter... but it's not hard

repeat wathever
  wait x mod milliseconds
  change things timefactor by pnumber
  draw next step
end repeat

BTW, this is dear to my animation routine in MoireX Volume 2 - the rev
screen saver...

http://www.monsieurx.com/modules.php?name=News&file=article&sid=160

but how many poligons can you get to move smoothly?

adding rotation ideas? swap and twist the object's rects? what if the
control is a movie and it's playing? ;)

anyone think rev should support opengl? How far can Rev take multimedia with
a simple idea?

cheers
Xavier
http://monsieurx.com/taoo

> -----Original Message-----
> From: use-revolution-bounces at lists.runrev.com 
> [mailto:use-revolution-bounces at lists.runrev.com] On Behalf Of MisterX
> Sent: Monday, October 24, 2005 7:04 AM
> To: 'How to use Revolution'
> Subject: RE: Help with image effect
> 
> Alex, 
> 
> Great effect!!!
> 
> Strange, my portable PC 1.6Ghz is faster than my 3Ghz PC ;)
> 
> 3Ghz = smooth transition
> 1.6Ghz = instantaneous...
> 
> what you could do is test the function to see how much time it takes.
> Given that, increment or decrement the number of transitions...
> 
> Also a percentage increase in size may look smoother but 
> that's just a habit and it may slow down things...
> 
> Last bit, that would be cool, is to switch layers so that the 
> zoomed image becomes the top image in the middle of the transition ;)
> 
> cheers
> Xavier
> 
> > -----Original Message-----
> > From: use-revolution-bounces at lists.runrev.com
> > [mailto:use-revolution-bounces at lists.runrev.com] On Behalf Of Alex 
> > Tweedly
> > Sent: Sunday, October 23, 2005 8:51 PM
> > To: How to use Revolution
> > Subject: Help with image effect
> > 
> > 
> > I want a nice, simple (?) visual effect:
> > 
> >  I have two images (which may be different sizes), and I 
> want to swap 
> > them over (such that each one stretches or shrinks to 
> occupy the space 
> > previously taken up by the other one).
> > 
> > I thought this would be simple ... loop some number of times, 
> > adjusting the "rect" of each image - then find a suitable 
> "wait" value 
> > to slow it down.
> > 
> > In fact, it is unbearably slow - even for medium sized 
> images (320*240 
> > swapping with a 320*480) each step is clearly visible.
> > For 2 images of 160*120 it's almost a smooth animation - 
> I'm not sure 
> > if it's just that they are smaller sizes, or if it's the 
> fact that the 
> > sizes remain the same.  (all on medium laptop - Pentium P4 
> 2.8G with 
> > low-end ATI graphics)
> > 
> > It does look OK on a top of the range Pentium laptop with ATI92xx 
> > graphics (my wife needs high-end hardware to play Sims :-), 
> but that's 
> > not exactly typical hardware yet.
> > 
> > Is there some other way I should be approaching this ?
> > 
> > > on imageSwap pImg1, pImg2, pNumber
> > >   local r1, r2
> > >   local dtlx, dtly, dbrx, dbry
> > >  
> > >   if paramCount() < 3 then
> > >     put 20 into pNumber
> > >   end if
> > >  
> > >   put the rect of img pImg1 into r1
> > >   put the rect of img pImg2 into r2
> > >    
> > >   put (item 1 of r2 - item 1 of r1)/20 into dtlx
> > >   put (item 2 of r2 - item 2 of r1)/20 into dtly
> > >   put (item 3 of r2 - item 3 of r1)/20 into dbrx
> > >   put (item 4 of r2 - item 4 of r1)/20 into dbry
> > >    
> > >   repeat with i = 1 to pNumber
> > >     set the rect of img pImg1 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 img pImg2 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
> > 
> > Thanks,
> > 
> > -- 
> > Alex Tweedly       http://www.tweedly.net
> > 
> > 
> > 
> > --
> > No virus found in this outgoing message.
> > Checked by AVG Free Edition.
> > Version: 7.1.361 / Virus Database: 267.12.4/146 - Release
> > Date: 21/10/2005
> > 
> > _______________________________________________
> > use-revolution mailing list
> > use-revolution at lists.runrev.com
> > Please visit this url to subscribe, unsubscribe and manage your 
> > subscription preferences:
> > http://lists.runrev.com/mailman/listinfo/use-revolution
> 
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage 
> your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution




More information about the use-livecode mailing list