go to Part:   previous   next   1   2   3   4   5   6   7   8   9   10   11 

Patterns Part 7

Getting the windows back

If you have quit Revolution yesterday, and now today you want to continue, you will probably just double-click the stack you saved.  But you may see that opening the saved stack will only show the Patterns window and not the Controls window.

To open the Controls window:  use the Application Browser, right-click the Controls substack and choose Go:

This is tedious!

We want the main stack to open the Controls when it starts up. To do that, tell the Patterns stack to open the Controls stack:

Easy!  Save your work.

The colour picker

Colours have three components:  red, green and blue.  This is because our eyes have three different sensitive components, one for sensing red, one for green and one for blue.

To make a colour picker we need three sliders.  Drag a slider to the controls window:

Set its name to "Red", the start value to 0, the endvalue to 255, the thumbposition to 0 and check the showvalue off.

Drag a new field next to the scrollbar and call it "Red", switch the locktext on:

Make the scrollbar a bit longer and the field a bit smaller, and put them next to each other.

Go to the script of the scrollbar, by using the application browser or by right-clicking on the scrollbar, and type:

on ScrollbarDrag

put the thumbposition of me into lRedIntensity

put lRedIntensity into field "Red"

set the pRedIntensity of stack "Patterns" to lRedIntensity

end ScrollbarDrag

 

 

Go into run mode and move the new slider:  the value is put into the field and we can't go outside the range 0 to 255.

What does our script do?

As soon as you start moving the scrollbar's blue dot, Revolution starts sending the message "ScrollbarDrag" to the scrollbar. This message comes repeatedly, all the time you hold the mouse down on the blue dot.

The script then repeatedly does three steps:

  1. First it looks at the position of the blue dot, and this is a number between 0 and 255, as we have set the limits.  It puts that number into the container lRedIntensity which is a container that we invented.
  2. Then it takes whatever number it just put into lRedIntensity and it puts it also into the field "Red".
  3. Lastly, it sets the property pRedIntensity of the Patterns stack to again that same number.

The property pRedIntensity did not exist, we invented it just now.  The Patterns stack now has a new property, and we will use that a lot later on.

Going Green and Blue

To make any colour we must also have a slider for green and blue.  We already have a slider and field for red, let's just copy it.

Go back to programming mode. Click the slider, then hold down the shift key and click also the field.  Both are now selected:

Release the mouse button and the shiftkey.  Hold down the option key then drag one of the two down.  A copy of both will appear:

If this does not succeed, use copy & paste from the edit menu.  Do it again, so we have three scrollbars and three fields:

Now, in the Application Browser you will see that we have three fields called "Red" and three scrollbars called "Red".  Select the middle ones and using the inspector, call them Green, select the bottom ones and call them Blue. Also change the scripts of the scrollbars so they use the correct colour names.

You can change the scripts fairly fast by using the find-and-replace of the script window.  Type command-F or click the binoculars at the bottom right of the script window.  Fill in the find and replace fields, then press Replace All.

Don't forget to Apply your changes.  And save your work too.

Displaying the colour

We have sliders but that's boring, we want to see the colour too.  Drag yet another field onto the Controls window and call it "CentralColour":

For its script write:

on Update

set the backgroundcolor of me to field "Red",field "Green",field "Blue"

end Update

 

This is a single line that takes the numbers from the three fields and combines them into a single Revolution colour.

We could have written it much longer, for example:

on Update

put field "Red" into R

put field "Green" into G

put field "Blue" into B

set the backgroundcolor of me to R,G,B

end Update

 

and this works just as well and may be a little easier to understand.

Good.  Apply and save.  Go to run mode and move the sliders.

Nothing happens!

Sending messages

Nothing happens because the field "CentralColour" does not get a message "Update"! from anyone.  We have to send a message explicitly.  And we must do it in each of the scrollbar scripts.

Add this line to each of the scrollbar scripts:

send "Update" to field "CentralColour"

When you have done that to all three scrollbars it should work.  Each time you move one of the blue dots the CentralColour field will get the message "Update" and it then takes the new colour numbers from the field and sets its own background colour.

Enough for this part.

(next part)