Page 1 of 1
How to decrease a columns height smoothly with elapsed time
Posted: Fri Jan 17, 2020 12:56 pm
by glenn9
Hi,
As part of a visual countdown timer project I'm trying to get my falling column to fall 'smoothly'. At the moment it decreases in height every second but in a very 'chunky' step like manner!
I've tried to experiment with subtracting milliseconds instead, but I'm tangling myself up in the logic and not getting anywhere!
Grateful for any help.
Code: Select all
repeat(field"Seconds")
# Seconds is the countdown start time
# tCol is the starting height of the column
# tHt is the 'remaining' height of the column
wait 1 second
subtract 1/field"Seconds" * tHt from tCol
set height of graphic"Col" to tCol
set the bottom of graphic "Col" to 50
end repeat
(Not sure if I need to include all the code but will do if it helps)
Re: How to decrease a columns height smoothly with elapsed time
Posted: Fri Jan 17, 2020 1:37 pm
by Klaus
Hi glenn9,
well
1/whatever is always < 1, so that is surely not what you want!
And LC cannot handle "fractions" of pixels, but doesn't throw an error however if we use them!
The trick in these case is not to use a repeat loop, but use "send xxx in yyy" until the countdown ends.
To give an example, I need to know:
How long (in seconds) is your "countdown" supposed to be?
What is the height of your graphic before the countdown starts?
Best
Klaus
Re: How to decrease a columns height smoothly with elapsed time
Posted: Fri Jan 17, 2020 2:58 pm
by dunbarx
Hi.
Assuming you have a field "X", something like this?
Code: Select all
on mouseUp
put the rect of fld "x" into tRect
put the bottom of fld "x" into tBot
repeat until the height of fld "x" = 5
set the height of fld "x" to height of fld "x" - 1
set bottom of fld "x" to tBot
wait 3
end repeat
set the rect of fld "x" to tRect
end mouseUp
Now this just runs. If you want to marry it to some other process, that is, when an element of that process goes in lockstep with the height of your control, you can just (pseudo):
Code: Select all
...
if one step occurs in yourProcess then set the height of fld "x" to height of fld "x" - 1
...
Craig
Re: How to decrease a columns height smoothly with elapsed time
Posted: Fri Jan 17, 2020 9:11 pm
by Klaus
HJi Craig,
"the rect" has no meaning in your script, this will work the same:
Code: Select all
on mouseUp
## put the rect of fld "x" into tRect
put the bottom of fld "x" into tBot
repeat until the height of fld "x" = 5
set the height of fld "x" to height of fld "x" - 1
set bottom of fld "x" to tBot
wait 3
end repeat
## set the rect of fld "x" to tRect
end mouseUp
If we want to use the rect for this task, do like this:
Code: Select all
on mouseUp
repeat
if the height of fld "x" = 5 then
exit repeat
end if
put the rect of fld "x" into tRect
add 1 to item 2 of tRect
set the rect of fld "x" to tRect
wait 3 WITH MESSAGES
end repeat
end mouseUp
Best
Klaus
Re: How to decrease a columns height smoothly with elapsed time
Posted: Fri Jan 17, 2020 9:47 pm
by dunbarx
Klaus.
Baby.
"the rect" has no meaning in your script,
What on earth can you mean? This isn't something from Humpty Dumpty, is it?
Craig
Re: How to decrease a columns height smoothly with elapsed time
Posted: Fri Jan 17, 2020 9:50 pm
by dunbarx
Oh, maybe I see what you had in mind.
I included that last line to restore the field to its original height. It does not have to be there, but surely has meaning.
Craig
Re: How to decrease a columns height smoothly with elapsed time
Posted: Fri Jan 17, 2020 10:25 pm
by Klaus
dunbarx wrote: ↑Fri Jan 17, 2020 9:50 pm
I included that last line to restore the field to its original height. It does not have to be there, but surely has meaning.
Oh, damn, so sorry, I must have missed that, not my day today...
