Prabrothers'

Quartz Composer Diary

Exercise Discussion

The first primer ended with us leaving an exercise for you to complete. It was set a bit tough so that you will get a chance to explore how various patch interact in Quartz Composer. Here's the discussion on how you might go about solving it. There are many ways to solve the exercise, this is the solution that we were hoping that you would arrive at with the material that was taught in the first primer. The answer was to connect two multiplexers in parallel to a multiplexer wired with a toggle.

Whenever faced with a complex problem in Quartz Composer, the idea is to break it down in to smaller problems so that you can tackle one at a time. Let us see how we can apply this advice in our exercise. From the problem definition, we know that we need an off button that gets depressed on clicking and get turned on on releasing. Next, when you click the button that has just turned on, it gets pressed and turns off. Let us concentrate on the first bit of a button turned off button getting pressed. You will know from your experience that a multiplexer and two states of a button is all you need to accomplish this.

Arrangement for Off States

Now you will notice that the routine is same for making an on button getting pressed. You need only replace the two states that goes into the multiplexer with On.png and On_Pressed.png and we get the desired effect of an On button getting depressed. To accomplish our mission, we need to make the button turn on and stay turned on as soon as we release the mouse button. This suggests a toggle coming into play as soon as you release the mouse button. But how would you toggle between the pressed as well as normal states of an off and on state? This is a tricky part of the question. The answer is that you need to connect these two off, off_pressed multiplexer and the on, on_pressed multiplexer to a new multiplexer.

Multiplexers in Parallel

The resulting structure of connecting two multiplexers in parallel to a new multiplexer

Now you need to drag in a noodle from the Mouse Down port of the interaction patch and connect to the Source Index port of both of the multiplexers. This is something that we were keeping for the second primer to reveal but were put out to you hoping that you would figure it out. If you failed don't worry, we put out this exercise just to make you dabble more in Quartz Composer. If you did figure it out, good job! What we now want to make happen is the actual toggle between the states. As soon as the mouse is down, we need to toggle from the off state to the on. Interpose a toggle patch such that it acheives this.

Interposing a toggle

The resulting structure of connecting two multiplexers in parallel to a new multiplexer

Now let's test out our code. Though the toggling is working, we see that as when the off state of the button gets depressed, we get the on_pressed state of the button instead of off_pressed. This suggests that there is a swapping required between the states. Let's do that. Here's what the finished composition looks like :

Solved Exercise

The finished composition

Here's a rundown on what is happening in the composition. When we first click on the off button, as the mouse button is pressed, the toggle sends a value 1 to the multiplexer connected to the billboard. This make it resort to Source#1 and pulls data from the source at that position, which happens to be multiplexer containing the on and on_pressed states. Here, the source index is determined by whether the mouse is down or not. Since the mouse is down as we make the click, the image is pulled out its Source#1. This lets on_pressed on to the billboard. When we release the mouse, the toggle is still outputting the value 1. This means the value is pulled from the same multiplexer as before, but now, for that multiplexer, the mouse button is not down and hence on state, instead of on_pressed is let out from Source#0 on to the billboard. A similar phenomenon happens when we click on the button. If you have understood how this works, making actions with multistate buttons would be a cinch. Now, let's learn some animation with Quartz Composer.

comments powered by Disqus