Cycle color of actor by tapping

Hey all, as you can tell from the title I am a total noob. What I'd like to accomplish is have the default white box actor cycle through red, blue and green when tapped. I have managed to get the box to change to one color by using the change attribute but I can not figure out how to get it to change to another color when tapped again. I have tried adding another change attribute and rule but that doesn't work either. Any help would be truly appreciated!

Comments

  • ArmellineArmelline Member, PRO Posts: 5,367

    I'd probably do it something like this.

    Change the self.Colour attribute to 0 and the default box colour to white if you want to start it as white.

  • HopscotchHopscotch Member, PRO Posts: 2,782
    edited October 2016

    Here is a simple version:

    Make an integer self attribute called ColorState in the actor, then add the following code:

    Rule: If Touch is pressed
             Change Attribute: self.ColorState = mod( self.ColorState+1 , 3 )
    End Rule
    
    Rule: If self.ColorState = 0
             Change Attribute: self.Color.Red = 1
             Change Attribute: self.Color.Green = 0
             Change Attribute: self.Color.Blue = 0
    End Rule
    
    Rule: If self.ColorState = 1
             Change Attribute: self.Color.Red = 0
             Change Attribute: self.Color.Green = 1
             Change Attribute: self.Color.Blue = 0
    End Rule
    
    Rule: If self.ColorState = 2
             Change Attribute: self.Color.Red = 0
             Change Attribute: self.Color.Green = 0
             Change Attribute: self.Color.Blue = 1
    End Rule
    

    A more flexible version:

    Create a table, lets call it T_ColorTable, with three real columns, and a text column. Label each column Red, Blue, Green and the last, Color. Now fill consecutive rows with the red, green and blue color values ( fractions between 0 and 1, e.g. 0.3).

    Advantage, easily extendable - just add more rows of colors.

    T_ColorTable

    Row      Red      Green    Blue     Color
    -------- -------- -------- -------- --------
    1        1        0        0        Red
    2        0        1        0        Green
    3        0        0        1        Blue
    4        1        0        1        Magenta
    5        0.5      0.5      0        Olive          
    

    Now make an integer self attribute called ColorState in the actor, then add the following code:

    Change Attribute: self.Color.Red = tableCellValue(T_ColorTable,self.ColorState+1,1)
    Change Attribute: self.Color.Green = tableCellValue(T_ColorTable,self.ColorState+1,2)
    Change Attribute: self.Color.Blue = tableCellValue(T_ColorTable,self.ColorState+1,3)
    
    Rule: If Touch is pressed
             Change Attribute: self.ColorState = mod( self.ColorState+1 , tableRowCount(T_ColorTable) )
    
             Change Attribute: self.Color.Red = tableCellValue(T_ColorTable,self.ColorState+1,1)
             Change Attribute: self.Color.Green = tableCellValue(T_ColorTable,self.ColorState+1,2)
             Change Attribute: self.Color.Blue = tableCellValue(T_ColorTable,self.ColorState+1,3)
    End Rule
    
  • SocksSocks London, UK.Member Posts: 12,822
    edited October 2016

    Here's another version . . .

    Real attribute = 'A'.

    When touch is pressed:
    --Change A to A+120
    --Change Red to cos(A)+0.5
    --Change Green to cos(A+120)+0.5
    --Change Blue to cos(A+240)+0.5

    . . . . . . . . .

    This cycles through Red > Blue > Green, but if you change the first Change attribute to -120 it will cycle Red > Green > Blue . . . if you change it to +1.40625 it will cycle through an 8bit colour palette (256 colours from Red to Red), or if you change it to +0.00002145767212 you will cycle around the entire 24bit colour palette, although it will take you 16,777,216 clicks to do so ! More usefully, +60 will cycle through Red > Magenta > Blue > Cyan > Green > Yellow > Red . . .

  • HopscotchHopscotch Member, PRO Posts: 2,782
    edited October 2016

    @Socks said:
    ... or if you change it to +0.00002145767212 you will cycle around the entire 24bit colour palette, ...

    "Crazy Colorful Color Clicker"

    Trademarked it yet @Socks? There is a song in there somewhere.

  • SocksSocks London, UK.Member Posts: 12,822

    @Hopscotch said:

    @Socks said:
    ... or if you change it to +0.00002145767212 you will cycle around the entire 24bit colour palette, ...

    "Crazy Colorful Color Clicker"

    Trademarked it yet @Socks? There is a song in there somewhere.

    A song, and an app, and probably a Broadway musical, going to get Danny DeVito to play me.

  • wdangelo@me.comwdangelo@me.com Member Posts: 2

    Thank you all so much! This is extremely helpful!

  • ToqueToque Member Posts: 1,188

    You could have four different colour boxes and use change image behavior.

Sign In or Register to comment.