A graphic that change the color all time

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
Asha
Posts: 21
Joined: Tue Apr 01, 2014 1:02 pm

A graphic that change the color all time

Post by Asha » Mon Apr 14, 2014 1:19 pm

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!
English is not my mother tongue

Klaus
Posts: 14192
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: A graphic that change the color all time

Post by Klaus » Mon Apr 14, 2014 1:26 pm

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)

Asha
Posts: 21
Joined: Tue Apr 01, 2014 1:02 pm

Re: A graphic that change the color all time

Post by Asha » Mon Apr 14, 2014 5:18 pm

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!
English is not my mother tongue

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: A graphic that change the color all time

Post by dunbarx » Mon Apr 14, 2014 5:48 pm

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

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: A graphic that change the color all time

Post by Simon » Tue Apr 15, 2014 2:21 am

Is there some fun coding going on without me?? :)

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: A graphic that change the color all time

Post by dunbarx » Tue Apr 15, 2014 4:55 am

Uh oh.

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

Craig

Asha
Posts: 21
Joined: Tue Apr 01, 2014 1:02 pm

Re: A graphic that change the color all time

Post by Asha » Tue Apr 15, 2014 11:26 am

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:
English is not my mother tongue

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: A graphic that change the color all time

Post by dunbarx » Tue Apr 15, 2014 1:55 pm

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

Asha
Posts: 21
Joined: Tue Apr 01, 2014 1:02 pm

Re: A graphic that change the color all time

Post by Asha » Wed Apr 16, 2014 3:30 pm

: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:
English is not my mother tongue

Klaus
Posts: 14192
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: A graphic that change the color all time

Post by Klaus » Wed Apr 16, 2014 3:42 pm

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

Asha
Posts: 21
Joined: Tue Apr 01, 2014 1:02 pm

Re: A graphic that change the color all time

Post by Asha » Wed Apr 16, 2014 4:05 pm

Thanks Klaus!! :P
English is not my mother tongue

Alex_CTZ
Posts: 21
Joined: Fri Jan 10, 2014 11:38 pm

Re: A graphic that change the color all time

Post by Alex_CTZ » Thu Apr 17, 2014 12:47 am

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,

Asha
Posts: 21
Joined: Tue Apr 01, 2014 1:02 pm

Re: A graphic that change the color all time

Post by Asha » Fri Apr 18, 2014 11:31 am

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:
English is not my mother tongue

Post Reply