Page 1 of 1

A graphic that change the color all time

Posted: Mon Apr 14, 2014 1:19 pm
by Asha
I know it must be a silly question, but I can't find how to do it in a simple way...

I want that a graphic change the color all time, like a button, how I can do that?

Thank so much!

Re: A graphic that change the color all time

Posted: Mon Apr 14, 2014 1:26 pm
by Klaus
HI Aha,

1. welcome to the forum! :D

2. change color all the time like a button?
Automatically every couple of seconds? When you click it?
Sorry don't get it 8)


Best

Klaus

P.S.
Wil move this thread to the "Beginner" section, HINT, HINT! 8)

Re: A graphic that change the color all time

Posted: Mon Apr 14, 2014 5:18 pm
by Asha
Thanks Klaus,
Sorry my english is not as good it should :oops:

I have a tabular graphic that increase over time, I want that when it reach to the top it make like a flashing effect, changing color all time.

Thank you!

Re: A graphic that change the color all time

Posted: Mon Apr 14, 2014 5:48 pm
by dunbarx
So much fun.

Don't tell Simon, but put this in a button script:

Code: Select all

on mouseUp
   startFlash
end mouseUp

on startFlash
   if the optionKey is down then exit to top
   if the backColor of me = "red" then set the backColor of me to "green" else set the backColor of me to "red"
   send "startFlash" to me in 30
end startFlash
Now as payment for this, you must write back and tell me what each line does. Why did I make two handlers? Why the optionKey thing? How are you going to make this sort of thing work in your project?

You will probably have questions, and that is fine. But you are supposed to be learning, not just asking for free code solutions. So do experiment, and do write back with those answers and thoughts.

Craig Newman

Re: A graphic that change the color all time

Posted: Tue Apr 15, 2014 2:21 am
by Simon
Is there some fun coding going on without me?? :)

Simon

Re: A graphic that change the color all time

Posted: Tue Apr 15, 2014 4:55 am
by dunbarx
Uh oh.

Uh, no Simon, er, what makes you think that? Um, how about those Mets?

Craig

Re: A graphic that change the color all time

Posted: Tue Apr 15, 2014 11:26 am
by Asha
Haha :lol:

Thank so much Craig! that's exactly what I need.

Well, my homework:
The first handler "on mouseUp" tells to LiveCode tht the action will start once someone push the graphic.
The second has a escape in the first line, in case we want it to stop, the second line makes it change the color depending the color it have now, and the last says how fast it got to change.

:roll:

Re: A graphic that change the color all time

Posted: Tue Apr 15, 2014 1:55 pm
by dunbarx
You get an "A".

Why not simply use a single "mouseUp" handler? Any reason to split them? Extra credit: Can you rewrite as a single handler just in case this would work just as well? How do you intend to get out of that "loop"? Pressing the optionKey is not likely to be the best way, no?

Craig

Re: A graphic that change the color all time

Posted: Wed Apr 16, 2014 3:30 pm
by Asha
:D

Well if we split them we can use the startFlash from another button and at the same time I don't think the "send "startFlash" to me in 30" will work inside a mouseUp, at least seem strange.

I'll show you how I implemented your code:

Code: Select all

on startFlash
   Global vFlash
   if vFlash = 0 then exit to top
   put 0 into count
   repeat with count = 0 to  vFlash
      add 1 to count
     if the backgroundcolor of graphic "s1" of  group ("legend" &  count)  = "red" then set the  backgroundcolor  of graphic "s1" of  group ("legend" &  count) to 217, 0, 0 else set the  backgroundcolor  of graphic "s1" of group ("legend" &  count)  to "red"
    if the backgroundcolor of graphic "s2" of  group ("legend" &  count)  = 241, 113, 51 then set the  backgroundcolor  of graphic "s2" of  group ("legend" &  count) to 236, 86, 36 else set the  backgroundcolor  of graphic "s2" of group ("legend" &  count) to 241, 113, 51
 send "startFlash" to me in 30
end repeat
end startFlash
Well I'll explain now :) , I have a routine that gets from database and then shows the data depending on the user you select, when you change the user it populates de information and in case the tabular graphic is full it start to flash, and because the ones nearest to the full are always on top the vFlash count how many of them need to flash... And if no one of the tabular data of the user is full then the flash effect stops.


I hope you understood and that my implementation don't seem so horrible :roll:

Re: A graphic that change the color all time

Posted: Wed Apr 16, 2014 3:42 pm
by Klaus
Hi Asha,

okie dokie :D

Maybe a couple of things:
1. Since you actually start your repeat loop at 1, you do not need to additionally manage a counter!
2. I am sure the "send startFlash..." should go OUTSIDE AFTER the repeat loop, right?
3. I added some CRs and "end if"s to make the whole thing better readable :D

Code: Select all

on startFlash
  Global vFlash
  if vFlash = 0 then
    exit to top
  end if
  ## put 0 into count
  repeat with count = 1 to  vFlash
    ## add 1 to count
    if the backgroundcolor of graphic "s1" of  group ("legend" &  count)  = "red" then
      set the  backgroundcolor  of graphic "s1" of  group ("legend" &  count) to 217, 0, 0
    else
      set the  backgroundcolor  of graphic "s1" of group ("legend" &  count)  to "red"
    end if
    
    if the backgroundcolor of graphic "s2" of  group ("legend" &  count)  = 241, 113, 51 then
      set the  backgroundcolor  of graphic "s2" of  group ("legend" &  count) to 236, 86, 36
    else
      set the  backgroundcolor  of graphic "s2" of group ("legend" &  count) to 241, 113, 51
    end if
  end repeat

  ## Only seend ONCE and AFTER the repeat loop, right?
  send "startFlash" to me in 30
end startFlash
Best

Klaus

Re: A graphic that change the color all time

Posted: Wed Apr 16, 2014 4:05 pm
by Asha
Thanks Klaus!! :P

Re: A graphic that change the color all time

Posted: Thu Apr 17, 2014 12:47 am
by Alex_CTZ
dunbarx wrote:You get an "A".

Why not simply use a single "mouseUp" handler? Any reason to split them? Extra credit: Can you rewrite as a single handler just in case this would work just as well? How do you intend to get out of that "loop"? Pressing the optionKey is not likely to be the best way, no?

Craig
haha why not simply use a, wow I dont even know what it is lololololol. Trying to learn to code proving difficult,

Re: A graphic that change the color all time

Posted: Fri Apr 18, 2014 11:31 am
by Asha
Alex :)

Learn to code is one of the most satisfactory thing that I did.

I know at first is confusing and strange, a lot of different languages out there.. I pick up a bit of each, the base of all of them is the same and is easier every time :P

Learning to program is exponential, every small step helps you to make bigger steps.

now learn what is a "mouseUp" handler :wink: