Text size increase effect

Visuals, audio, animation. Blended, not stirred. If LiveCode is part of your rich media production toolbox, this is the forum for you.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
SWEdeAndy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 257
Joined: Sat Aug 16, 2008 9:48 am
Location: Stockholm, Sweden
Contact:

Text size increase effect

Post by SWEdeAndy » Tue Oct 17, 2017 4:08 pm

Hi all,

I want to create an effect where a word in a field grows from textSize 5 to 100 (or something similar), so that it appears to start small and expand on the screen towards the viewer.

I’ve tried this, but it is not as smooth nor as fast as I would like it to be:

Code: Select all

local sCount

command prepareResize
   put 5 into sCount
   set the textSize of fld 1 to sCount
   doResize
end prepareResize

command doResize
   lock screen
   add 1 to sCount
   set the textSize of fld 1 to sCount
   wait 0 milliseconds with messages ## Having this or not has no effect
   if sCount < 100 then send doResize to me in 75 milliseconds
   unlock screen
end doResize
If I increase textSize by bigger steps, it gets more choppy (naturally). If I set the send delay lower than around 75 milliseconds then it goes too fast for Livecode to keep up, it seems, resulting in textSize increasing by jumps of 2 or 3, making it more choppy.

So, is there a way to achieve a fast and smooth increase of the text? Am I on the wrong track? Should I turn the word into an image and increase the size of that instead?

I’ll be wanting to have this effect going on for several fields/words in parallel, e.g. names taken dynamically from a list, popping up all over the screen. So it has to be efficient enough not to cause lagging when used for multiple objects.

Any ideas?

/Andreas
Andreas Bergendal
Independent app and system developer
WhenInSpace: https://wheninspace.se

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Text size increase effect

Post by [-hh] » Tue Oct 17, 2017 6:40 pm

Your approach is, TMHO, very dependent of the font quality (sizes must be scaled) and of all the other adjustments LC has to do for the field after changing the textsize.

Instead you could try the following approach that uses images (snapshots). Works here smoothly with 4 one-line-fields.
Depending on the number and size of your objects you may adjust the available parameters "tStep" and "tTimeStep".

Code: Select all

local sCount, iNum, w0, h0, l0, t0, tStep, tTimeStep

command doResize k,ii
  lock screen; lock messages
  add tStep to sCount[k]
  set rect of img ii to \
        (l0[k], t0[k], l0[k]+sCount[k]*w0[k]/100, t0[k]+scount[k]*h0[k]/100)
  if sCount[k] < 100 then send "doResize k,ii" to me in tTimeStep millisecs
  else
    hide img ii; show fld k
  end if
  unlock screen; unlock messages
end doResize

-- demo with 4 fields
on mouseDown
  lock screen; lock messages
  put 4 into tStep -- increase parameter
  put 32 into tTimeStep -- timeLoop parameter
  repeat with j=1 to 4
    put 0 into sCount[j]
    put ("img"&j) into iNum[j]
    -- delete, at least while developing
    if there is an img iNum[j] then delete img iNum[j]
    if there is no img iNum[j] then create invisible img iNum[j]
    set resizequality of img iNum[j] to "best"
    export snapshot from fld j to img iNum[j] as PNG
    put the width of img iNum[j] into w0[j]
    put the height of img iNum[j] into h0[j]
    put the left of fld j into l0[j]
    put the top of fld j into t0[j]
    set rect of img iNum[j] to (l0[j], t0[j], l0[j]+1, t0[j]+1)
    hide fld j
    show img iNum[j]
  end repeat
  repeat with j=1 to 4
    doResize j, iNum[j]
  end repeat
  unlock screen; unlock messages
end mouseDown
When using a factor (multiplicative step) that increases from 0 to 1 instead of the additive step you can also achieve kind of "easing" (increases faster for small sizes).
shiftLock happens

SWEdeAndy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 257
Joined: Sat Aug 16, 2008 9:48 am
Location: Stockholm, Sweden
Contact:

Re: Text size increase effect

Post by SWEdeAndy » Wed Oct 18, 2017 9:27 am

Brilliant, thanks a lot, that's just what I need!

I was thinking snapshots might be a solution, but haven't worked with that technique before. With this 'crash course' you have put me on the right track.

I've started to adapt your script to the kind of action I'm designing and it seems to work perfectly so far.

Thanks again!
/Andreas
Andreas Bergendal
Independent app and system developer
WhenInSpace: https://wheninspace.se

MaxV
Posts: 1579
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: Text size increase effect

Post by MaxV » Wed Oct 18, 2017 12:47 pm

I suggest this solution easy and cool:
  • put a field
  • put a check box
  • insert the following code in the checkbox
########CODE to copy and paste#######
on mouseUp
set the cursize of me to the textsize of field 1
cooleffect
end mouseUp

on cooleffect
if the hilite of me then
put the cursize of me into temp
if temp > 100 then set the incr of me to -1
if temp < 5 then set the incr of me to 1
add the incr of me to temp
set the textsize of field 1 to temp
set the cursize of me to temp
send cooleffect to me in 5 millisec
end if
end cooleffect
#####END OF CODE generated by http://tinyurl.com/j8xf3xq with livecode 9.0.0-dp-6#####
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

SWEdeAndy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 257
Joined: Sat Aug 16, 2008 9:48 am
Location: Stockholm, Sweden
Contact:

Re: Text size increase effect

Post by SWEdeAndy » Wed Oct 18, 2017 1:27 pm

Wow, yes, that works too! It basically does the same as my original script, but way faster and smoother.
What is it in my script that slows it down so much compared to this one?

Thanks!
/Andreas
Andreas Bergendal
Independent app and system developer
WhenInSpace: https://wheninspace.se

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7215
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Text size increase effect

Post by jacque » Wed Oct 18, 2017 8:21 pm

The "wait 0" line is making it slower. I removed that and set the interval to 5 milliseconds in your original script and it looks very smooth to me:

Code: Select all

local sCount

command prepareResize
   put 5 into sCount
   set the textSize of fld 1 to sCount
   doResize
end prepareResize

command doResize
  lock screen
  add 1 to sCount
  set the textSize of fld 1 to sCount
  if sCount < 100 then send doResize to me in 5 milliseconds
  unlock screen
end doResize
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

SWEdeAndy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 257
Joined: Sat Aug 16, 2008 9:48 am
Location: Stockholm, Sweden
Contact:

Re: Text size increase effect

Post by SWEdeAndy » Wed Oct 18, 2017 8:55 pm

Indeed, the original script, when I try it again now in a new stack, is quite smooth. :oops:
The "wait 0" line seems to have marginal effect, but better without it. (I've learned somewhere that "wait 0..." would sometimes make things smoother, but maybe not the way I applied it.)

Even adding "move fld 1 relative 0,-1" for each iteration, to compensate for the downward drift, didn't slow it down.

Anyway, as always, I learned some new things here, and the snapshot method is very flexible and good to know.

Thanks guys, you're the best!
Andreas Bergendal
Independent app and system developer
WhenInSpace: https://wheninspace.se

Post Reply

Return to “Multimedia”