An Experiment with Decorators
I’ve finally found some free time to play around with some of the experimental ideas I’ve had in my head, so I decided to start with a fun little decorator demonstration. I haven’t had alot of opportunities to play around with the Decorator Pattern much, so I wanted a project that pretty much forced me to use it.
Here’s what it looks like so far
This project has also given me the opportunity to experiment much more extensively in the process of creating custom UIComponents for the Flex framework, including the fluid resizing effect (which you can observe by adjusting your browser size when you check out the sample) and exposing custom configurable styles.
I plan to add a lot more to it, but for now you can refresh your browser and observe how behaviors are “decorated” onto the dummy shapes on runtime. So far the decorators that a dummy can recieve are:
- DeflectModifier (causes the bouncing effect off boundaries)
- RotateModifier (rotates the dummy clockwise)
- MoveModifier (moves the dummy forward)
- DoublerModifier (triggers the behavior of all decorators stacked below it twice)
I’ve already got some ideas to create fading/color effects, chaos, and a few other effects. I’ll get back to you once there’s something a bit more interactive to play with =]
UPDATE:
So, after showing this to several people, the recurring first response I heard was “the boxes should bounce off each other,” so I went ahead and added collision detection into the experiment. Except, to further my study, I decided to do so using a CollisionModifier to decorate the dummy sprites with. With various combinations of the CollisionModifier and the DeflectModifier, you can see how three different distinct behaviors appear between the sprites. Some bounce off each other, some push each other, and some just ignore the others.


Good job Steve! You got me wasting the better part of an hour looking at your little creation
Comment made by Ruben Swieringa on April 11, 2007 @ 7:20 am
Hehe thanks. I find that the “updated” version can be even more distracting though =]
Comment made by Steve on April 12, 2007 @ 9:31 am