code to change color as state changes