Click here to Skip to main content
Click here to Skip to main content

Busy Dizzy Bee-sley Spirographic Animation in Expression Blend & Silverlight

By , 11 May 2010
 

Introduction

Welcome to my 8th Beginners tutorial for Expression Blend & Silverlight. And this one is just for fun!!!

A live example thanks to Defwebserver can be found at http://silverlight.adefwebserver.com/alanbeasley/busybeesite/. (This Bee has been at the Cider!)

A clearer example of what is going on can be seen at http://silverlight.adefwebserver.com/alanbeasley/sillyshapes/SillyShapesSite/

This short tutorial will show how to use Ken Johnson's excellent Spirographic article to create seemingly random motion without a single line of code! We will also be introducing the PathListBox, UserControls, Behaviours & Storyboards for the first time in my tutorials.

Previous Tutorials

Background

With the release of Blend 4 came the new PathListBox, which allows "Path to Motion". A feature already present in Flash, & up until now missing in Silverlight. Basically this allows one object to be set to follow the line/path of another object. Be this a square, a circle, or any other vector line/path...

While this is great, it does have its drawbacks, as most shapes easily drawn are fairly basic & not complex enough to simulate what appears to be random motion. That is until the brilliant Spirograph article by Ken Johnson! After seeing Ken's article, I asked if it was possible for Ken to create a Path Export feature for the created Spirographic shapes. And before I could blink, there it was! (Thanks again Ken - Please vote on Ken's Spirographic article if you haven't already!!!)

What Ken has effectively done, is create a whole new set of Primitives for Expression Blend & Silverlight. Which I believe could/should lead to all sorts of applications for these Path shapes. I am obviously just showing one such possibility, but I believe there are many many more...

I've been itching to do a tutorial involving the PathListBox, & this was far to good an opportunity to let slip by. So while this tutorial is just a bit of fun, I will be showing how use the basics of the PathListBox in creating a basic animation in Silverlight.

Let's Get Started

Firstly, we need to setup a new Silverlight project in Blend calling it "BusyBee".

Next, we need something to animate along the Path, so bring on the star "Busy Dizzy Bee-sley" (Me) or BusyBee for short.

Download the BusyBee UserControl from here, & add both files to your Project.

Next Rebuild your Project to make the BusyBee available as an Asset in Blend.

Select BusyBee from the Assets menu, as shown in the image below:

Now double click on the BusyBee UserControl to add it to the MainPage.

Next, we need to add some Spirographic shapes to our project, so click on this link to access Ken Johnson's Spirographic shapes.

Select Install, & as long as all goes well, you should be presented with the same screen as the image below:

Select Shape Explorer, which should bring up the screen as shown in the image below:

Now select an appropriate Spirographic shape for BusyBee to follow.

(I would suggest you keep it simple, & choose a shape without any sharp turns as the main Path for BusyBee to follow).

I have chosen a Rose with values of A=10, N=4 & D=3, as shown in the image below:

Now select the Export feature in the top left corner, & choose Export Path XAML as shown in the image below:

This will bring up a window showing all the Path information for this Spirographic shape.

Now the easiest way to input this into Blend, is to Copy just the Path information data inside the quotes "" to the Clipboard.

Then go back to Blend, insert a Rectangle onto the MainPage & convert it to a Path.

Now select the Path Data in the XAML, & Paste in the Spirographic Path Data.

In the Artboard, the Rectangle should now look like the Spirographic shape, as shown in the image below:

(For clarity, I have temporarily hidden BusyBee.)

In the Objects and Timeline, select the Path & rename it to "BusyBeeMotionPath".

Set the Width & Height to 240x240, & the Horizontal & Vertical Alignment to Centre.

This should place the Spirographic shape centrally in the Artboard, as shown in the image below:

Now insert a PathListBox into the Root, & place the BusyBee element inside of the PathListBox, as shown in the image below:

(This makes the BusyBee element a child of the PathListBox, & the PathListBox can have multiple children. The spacing between these children is controlled by the Padding, which by default is set to 10).

Now select the PathListBox & in the LayoutPaths, set the "BusyBeeMotionPath" as the LayoutPath for the child BusyBee to follow:

In the Artboard, BusyBee should now be placed in the centre (the start) of the BusyBeeMotionPath.

Now, place the mouse pointer in the Start section of the Layout Paths & drag to the right.

This should move BusyBee along the BusyBeeMotionPath, reaching the end of the Path at 100%.

Run the application & review the results! Nothing happens!!!

This is because we do not have a Storyboard for the animation process...

So still with the PathListBox selected, click on the + icon to add a Storyboard to the Project.

Name this Storyboard to "BusyBeeMotion01" & click OK.

This will open a Timeline next to the Objects and Timeline. (Use the F6 key to change to Animation Layout in Blend).

Go to 12 seconds on the Timeline & in the Layout Paths, set the Start to 100%.

Play the Animation & in the Artboard, BusyBee should move along the BusyBeeMotionPath, reaching 100% at 12 seconds.

Now select the BusyBeeMotion01 Storyboard itself, as shown in the image below:

In the Properties tab, change the RepeatBehaviour for the BusyBeeMotion01 to "Forever", as shown in the image below:

Now Run the Application again to review the results, & still nothing happens!!!

This is because the BusyBeeMotion01 Storyboard is not being fired (started) when the application is Run (loaded).

So we need to set a Behaviour, to initiate the BusyBeeMotion01 Storyboard for when the Application is Loaded.

Firstly close the BusyBeeMotion01 Storyboard, using the X, as shown in the image below:

Then in the Assets tab, select Behaviours & find the ControlStoryboardAction Behaviour.

Click & drag the ControlStoryboardAction onto the PathListBox, as shown in the image below:

In the Properties tab, set the EventName to "Loaded" & the Storyboard to "BusyBeeMotion01", as shown in the image below:

Now Run the Application, & with a bit of luck, BusyBee should follow the BusyBeeMotionPath.

However, "Busy Dizzy Bee-sley" (BusyBee) is only facing left, & not looking where he is going. (Like me driving!!!)

To change this, & make BusyBee turn as he tracks along the BusyBeeMotionPath, we need to change the Orientation of the PathListBox to "OrientToPath".

Run the Application again to review the results.

BusyBee, or Busy Dizzy Bee-sley now runs backwards. (Exactly how I drive!)

So select BusyBee & in the Transform section, Flip BusyBee along the X axis.

Run the Application again & with a bit of luck, BusyBee will now be facing in the right direction when following the BusyBeeMotionPath.

Now to make BusyBee's motion a bit more random, & we can do this by making the BusyBeeMotionPath follow a Motion Path of its own.

Firstly select both the BusyBeeMotionPath & the PathListBox,  & choose Group Into > Grid.

Then go back to Ken Johnson's Spirographic shapes, to pick out another shape to use as a Motion Path.

I have chosen a Lissajous, with values as shown in the image below:

(Use the same process as we did before, by copying the Path Data into a Rectangle, that you have converted to a Path in Blend 4).

Rename this new Path to "ParentMotion", set the Width & Height both to 200 & the Horizontal & Vertical Alignment to Center.

Insert a new PathListBox, & rename it to "ParentPathListBox".

Select the Grid & place inside the ParentPathListBox, as shown in the image below:

Select the ParentPathListBox & in the Layout Paths section, set "ParentMotion" as the LayoutPaths.

In the Artboard, the BusyBeeMotionPath is now attached to the ParentMotion.

Select the ParentPathListBox, & create a new Storyboard called "BusyBeeParentMotion".

Go to 4.5 seconds on the Timeline, & in the Layout Paths change the Start to 100%. (Close the Storyboard once finished)

Next select the BusyBeeParentMotion & set the RepeatBehaviour to Forever.

Then drag a ControlStoryboardAction Behaviour onto the ParentPathListBox.

Set the EventName to "Loaded", & the Storyboard to "BusyBeeParentMotion".

Run the Application & review your results.

Now this may not look very realistic, as the Motion Paths are a distraction from BusyBee's motion.

So select both the BusyBeeMotionPath & the ParentMotion Path, removing the Fill & Stroke for both.

Run the Application again to see the results.

This is better, & improvements can obviously be made by playing with different shapes, adjusting the Storyboard animations, & maybe using a further parent Path.

Fly Busy Dizzy Bee-sley, Fly!

For me there is one last thing to do, & that is to make Busy Dizzy Bee-sley's (BusyBee) wings flap.

So in the Project tab, double click BusyBee, to open this UserControl in the Artboard.

Create a new Storyboard, call it "BusyBeeWingsFlap" & hit OK.

Expand the Tree to reveal all the element, & select TopWing1, TopWing2, BottomWing1 & BottomWing2, as shown in the image below:

Now set a Keyframe at time 0.0 seconds, move the timeline to 0.4 seconds & set another Keyframe.

Move the Timeline to 0.2 seconds & select the "TopWing1" element, as shown in the image below:

In the Artboard, drag the top of the Wing down, so it looks like the image below:

(This edit will automatically generate a Keyframe for the element, at 0.2 seconds.)

Repeat the process on the remaining 3 Wings, as shown in the image below:

Select the BusyBeeWingsFlap Storyboard itself, & set the RepeatBehaviour to "Forever".

Close the Storyboard, & drag a ControlStoryboardAction onto the Layout Root.

Now set the EventName to "Loaded", & the Storyboard to "BusyBeeWingsFlap".

Run the Application & review the results. - Job Done!!!

If you have enjoyed this bit of fun, then please VOTE!!!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Alan Beasley
User Interface Analyst
United Kingdom United Kingdom
Member
I've been playing with computers since my first Acorn Electron, & after blowing up a few ZX Spectrums. I moved on to the C64 & Amiga, & eventually reluctantly on to the PC.
 
I have learnt a wide set of skills during my 38 years of existence, living in the UK, on the sunny south coast.
 
My main area of expertise is Graphic/Visual Design, Usability & UI Design. I am not a programmer, but am fairly technically minded due to studying Mechanical Engineering at Uni.
 
I have work both Freelance & for IBM as a Graphic Designer, & am skilled in the usual graphics packages like, PhotoShop, CorelDraw or Illustrator, Premier, Dreamweaver, Flash etc.
But I originally started with Lightwave & 3D animation.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionFiles are missingmemberDesCBUDD1 Jan '12 - 8:05 
The directories at:
 
http://www.eightowls.com/clickonce/GeometryDemonstration/Application%20Files/[^]
 
are empty.
QuestionI can't download Ken Johnson's Spirographmemberdatcambridge22 Oct '11 - 14:33 
that link did die :(
GeneralMy vote of 5memberRichard Waddell20 Nov '10 - 8:12 
Thanks, just what I needed.
Generaloff topicmemberK.Ostrouska17 May '10 - 21:04 
Silverlight Mad | :mad:
I use Opera and i tried to run the demo. No way. MS send me to the silverligt download site to install it, but it is not compatible with that browser. It works for IE, Firefox and Chrome, nothing else.
Somehow typic Microsoft.
Of course i can use another(i have IE8 and Firefox installed to) but i lost my interest.
Web extensions should be browser and OS independent. Otherwise i feel like a hostage with it. No one has the right to reap the web.
I work with .NET in C# since 2002. In this moment, i would really like to learn Java and Adobe Flash and do something in the right direction.
Sorry for my emotional release.
Kruno

GeneralRe: off topicmemberAlan Beasley17 May '10 - 22:35 
Wow, you needed that! (Probably saved your monitor from flying across the room...) Laugh | :laugh:

Your right, it should work with all browsers... However I am unsure if this is a Opera, or a Microsoft issue!
I'd feel it is more lightly a Opera issue, as Microsoft really want to put Silverlight everywhere. I'd hope they have given up on pushing IE quite so hard, & have admitted there is room for other browsers.
 
Not so sure that Flash & Java is the way forward, as I think Adobe is fighting for its life regarding Flash. So think your about 8-10 years too later in thinking about learning Flash. I view Silverlight & HTML5 as the technologies of the future. But I could be wrong...
 
We are all in this industry to earn money, & mobile device development is where the big bucks are. And I'm sure you are aware, that Flash doesn't really have a piece of this pie. I'm not saying that Silverlight will dominate this market, as it has its issues. (It's currently driving me nuts on a project I'm doing with Defwebserver (Silverlight MVP), but you have to put your money somewhere, & Flash would be the last horse I would back...
 
Don't apologise for your outburst, you said nothing offensive to anyone. We all need a good rant now & then!!! (Stops you beating your hardware to death) Big Grin | :-D

If I could code, I'd be dangerous... My Blog[^]

GeneralRe: Hello AlanmemberAlan Beasley14 May '10 - 23:14 
hopefully done pal - Delete your eamil from your message mate! Unless you just love the spam!!! Big Grin | :-D
 
Sacha Barber wrote:
I'll look forward to hearing from you champ.

 
That's "Chump" to you pal!!! Laugh | :laugh:

If I could code, I'd be dangerous... My Blog[^]

GeneralRe: Hello AlanmvpSacha Barber15 May '10 - 0:00 
Done, thanks for replying.
Sacha Barber
  • Microsoft Visual C# MVP 2008-2010
  • Codeproject MVP 2008-2010
Your best friend is you.
I'm my best friend too. We share the same views, and hardly ever argue
 
My Blog : sachabarber.net

GeneralVery cool.. Another GREAT article..memberCastleSoft13 May '10 - 1:24 
Wow.. Another great article..
GeneralRe: Very cool.. Another GREAT article..memberAlan Beasley13 May '10 - 1:58 
Thanks Andrew, glad you liked it! Big Grin | :-D
 
Ken's article deserved a demo regarding the possibilities...

If I could code, I'd be dangerous... My Blog[^]

GeneralThank you for your work.memberBryanWilkins12 May '10 - 6:45 
From those of us who are trying to learn Silverlight 4. Thank you. And by the way, have a 5 from me too!
Smile | :)
-Bryan
 
My latest programming adventure was coding the multimedia features for the Rip Ride Rockit coaster at Universal Studios Florida. I love my job.

GeneralRe: Thank you for your work.memberAlan Beasley12 May '10 - 7:27 
Thanks again Bryan, & for leaving a comment (again) Big Grin | :-D
 
We are all learning, & it is my please regarding the design side of things in Expression Blend.
 
I also had a lot of fun with this one! Smile | :)
 
But I do wonder if I should have used the spirographic shapes the other way around to control the motion. As BusyBee would have turned left & right if I had used the Lissajous first...

If I could code, I'd be dangerous... My Blog[^]

JokeI wish I didn't know you so wellmemberJason Young 175612 May '10 - 4:29 
Fly Busy Dizzy Bee-sley, Fly!, I see what you've done there Beasley..., wish I hand't but I did, have a 5 anyway buddy and stop pestering me to read your articles, some of us have real work to do Smile | :)
GeneralRe: I wish I didn't know you so wellmemberAlan Beasley12 May '10 - 4:39 
Thanks mate, you are so kind!!! Sigh | :sigh:
 
I'm sure you have lots of work to do, I'd suggest you write better code! Big Grin | :-D
GeneralExcellentmemberMarcelo Ricardo de Oliveira11 May '10 - 16:47 
Well done, Alan, 5 from me
 
We are living in the age of spirographics Smile | :)
Take a look at XNA Snooker Club game here in Code Project.

GeneralRe: ExcellentmemberAlan Beasley12 May '10 - 1:26 
Thanks Marcelo, it was just a bit of fun really to demo Ken's excellent work.
 
Nothing in comparison to your XNA Snooker Club[^] & I can't wait to see your next article!!! Big Grin | :-D
GeneralRe: ExcellentmemberMarcelo Ricardo de Oliveira13 May '10 - 0:21 
Thanks, Alan! I hope I finish the next article soon Smile | :)
Take a look at XNA Snooker Club game here in Code Project.

QuestionBut, How do I put code behind to this??memberdefwebserver11 May '10 - 4:09 
Ok I gave you a 5, but HOW am I suppose to make a View Model using this? I'll figure something out...
 
Oh yeah, great work!
AnswerRe: But, How do I put code behind to this??memberAlan Beasley11 May '10 - 4:19 
defwebserver wrote:
but HOW am I suppose to make a View Model using this

 
Errr? Dunno! But you seem to be under the misunderstanding that us designers give a crap damn! WTF | :WTF:
 
And I know for a fact, that you have bigger fish to fry than play silly buggers with this!!! Laugh | :laugh:
 
Thanks Michael!
GeneralBee-utifulmemberKenJohnson11 May '10 - 3:39 
Looks great, made me smile.
 
Ken
GeneralRe: Bee-utifulmemberAlan Beasley11 May '10 - 3:57 
Thanks Ken, it was just a bit of fun, & you did all the hard work in your article[^]
GeneralI think this would be so much better if the paths had bananas and used baboons, then and only then can I give this a 5.mvpSacha Barber11 May '10 - 1:21 
So fix that and ill give it a 5. Ha Ha, nah have a 5
Sacha Barber
  • Microsoft Visual C# MVP 2008-2010
  • Codeproject MVP 2008-2010
Your best friend is you.
I'm my best friend too. We share the same views, and hardly ever argue
 
My Blog : sachabarber.net

GeneralRe: I think this would be so much better if the paths had bananas and used baboons, then and only then can I give this a 5.memberAlan Beasley11 May '10 - 1:31 
Don't be so silly, Baboons are an endangered species thanks to you!!! Cry | :((
 
(Also the word play doesn't work with my name)
GeneralYou are one busy beememberlinuxjr11 May '10 - 0:37 
Thanks for sharing this. Have a five from me.
GeneralRe: You are one busy beememberAlan Beasley11 May '10 - 0:49 
Thanks linuxjr, I just had to play with Ken's spiro shapes!
 
They are so cool, & i'm sure I will be using them in other stuff!!! Big Grin | :-D

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130523.1 | Last Updated 11 May 2010
Article Copyright 2010 by Alan Beasley
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid