![]() ![]() ![]() Lower numbers are dark red and higher numbers are a brighter red. Each through the loop the number representing the red color is incremented by the value of the ColorChangeRate variable, which is either 10 or -10. To keep this simple, the code adjusts only the red color value between 100 and 255. How do we make the color change gradually? By adjusting the value of one or more of the colors at each clock tick. As you can see below, the three values are bundled into a list. The make color block converts three numbers (for red, green and blue) into a color value for assigning to the button’s BackgroundColor. The interesting part of the program that changes the color are the two part inside the Clock1.Timer event handler: (1) the use of the make color block, and (2) the method of selecting and changing the colors at each timer tick. The button handler for the start button sets TimerEnabled to true, and the stop button handler sets it to false. When the program starts, the timer is turned off by setting the Clock1.TimerEnabled property to false. If positive, then the color value is incremented by the amount shown if negative, then the color changes in the other direction. We begin by creating 3 variables to hold the values of red, green and blue, plus one extra variable that specifies the amount and direction of the color change. In App Inventor, the “amount” of each color red, green or blue is specified with a number from 0 to 255. All possible colors may be created by mixing various levels of red, green and blue colors. However, colors may also be generated from a set of numbers. In the previous tutorial on button colors, the color property was set using “color swatches”. At each clock tick, the color property of the button is set to a new color.īy making the tick events occur rapidly, the color value may be adjusted in small increments. The clock generates an event at a specified interval – think of this as being like a “clock tick”. The key to making color change continuously is the use of the clock as a timer. In the button properties, set the button shape to “oval”.ĭrag a clock component into the Designer – the Clock will appear as a non-visible component at the bottom of the Viewer. How to implement a button that continuously changes color, as demonstrated in this video example:Ĭreate a simple user interface with two buttons – one to start the color change and the other to stop the color changes. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |