More send in time

Cubist at aol.com Cubist at aol.com
Tue Jul 1 03:24:01 EDT 2003


sez pixelbird at interisland.net:
>What I came up with is this base to work from. It works great and seems very
>stable. It's a scrolling field with upper and lower sections covered by
>translucent graphics and an open box across the center (where the eventual
>selection will take place). It has a few repeated lines at the head and tail
>such that it smooth-scrolls endlessly in either direction.
>
>on endlessScroller
>   constant scrollSpeedInterval = 10 -- will be a global later
>   if the mouse is up then exit endlessScroller
>   if within(graphic "upScrollArea", mouseLoc()) then
>     -- wrapover:
>     if the vScroll of fld 1 = 0 then set the vScroll of fld 1 to 1345
>     set the vScroll of fld 1 to (the vScroll of fld 1) - 1
>   else if within(graphic "downScrollArea", mouseLoc()) then
>     -- wrapover:
>     if the vScroll of fld 1 „ 1345 then set the vScroll of fld 1 to 0
>     set the vScroll of fld 1 to (the vScroll of fld 1) + 1
>   end if
>   send "endlessScroller" to me in scrollSpeedInterval milliseconds
>end endlessScroller
   Stop the presses! This looks like a job for... the MOD squad! Yes, MOD 
(short for "modulo"), the mild-mannered function which can make a perfectly 
normal counter cycle thru a limited number of values with no difficulty whatsoever! 
Here is an example of using MOD to cycle thru values from 1 to 10.

  put 1 into Fred
  repeat
    put 1 + (Fred mod 10) into Fred
  end repeat

   In this loop, the value of Fred increments from 1 to 10, and it does this 
over and over again. And here's a slight variation:

  put 1 into Fred
  repeat
    put (Fred + 1) mod 10 into Fred
  end repeat

   We again get the "eternal cycle" routine... but *this* time, it goes from 
*0* to *9*. Another slight variation:

  put 1 into Fred
  repeat
    put 1 + ((Fred + 10) mod 10) into Fred
  end repeat

   THis one cycles from 1 to 10 -- how boring -- but what's up with that 
redundant "+ 10" in there? Patience, my son, and all will become clear in the next 
variant:

  put 1 into Fred
  repeat
    put 1 + ((Fred + 10 - 2) mod 10) into Fred
  end repeat

   The first time thru the loop, Fred is 1. (1 + 10 - 2) is 9; 9 mod 10 is 9; 
and 9 + 1 is 10. Therefore, the first time thru the loop, Fred changes from 1 
to 10. Second time around, (10 + 10 - 2) is 18; 18 mod 10 is 8; and 8 + 1 is 
9 -- in other words, Fred changes from 10 to 9.
   In other words, the -2 in here makes the counter run *backwards*, from 10 
down to 1!

   Here, at last, is a "final" tweaked version of the EndlessScroller 
handler. Use it in good health...


on endlessScroller

  constant scrollSpeedInterval = 10 -- will be a global later

  if the mouse is up then exit endlessScroller

  if within(graphic "upScrollArea", mouseLoc()) then
    set the vScroll of fld 1 to ((the vScroll of fld 1) + 1343) mod 1345
  else if within(graphic "downScrollArea", mouseLoc()) then
    set the vScroll of fld 1 to ((the vScroll of fld 1) + 1345) mod 1345
  end if

  send "endlessScroller" to me in scrollSpeedInterval milliseconds

end endlessScroller

   Hope this helps...



More information about the use-livecode mailing list