Category Archives: ICM504

Weekend work in ActionScripting

First Iteration of the final project for ICM504 is well underway. I broke down and bought two additional books for my use. One was the O’Reilly ActionScript Cookbook (lovely organization for a reference book, I must say) and the other was Foundation ActionScript 3.0 Animation. The Animation text is worth it just because it explains the math foundations for use with realistic motion simulations.

However, working at home was interrupted slightly by the logistics of sharing computer access between two full time students. I ended up reading on the couch while my significant other was working on the computer. I didn’t want to let the opportunity to actually use some downtime on a Sunday for getting ahead on my final projects, so I buckled under and set about coding with pen and paper.

And therein lies the difference

My challenge with any computer language has always been getting to a level of basic competency in -writing- the code from a blank file. For some reason, having to work everything out on paper first (not pseudocode, but actual code) made a lot of difference to me. I started slowly and complained about having to do multiple crossouts and rewrites, but the slowness of writing by hand meant that I actually made a few connections mentally with the coding process, connections which were tenuous at best previously.

By the end of the afternoon, I had spent about 6 hours in the living room working on coding by handwriting. I had progressed from the tortured beginnings and was actually starting to really just think about the steps involved and my mind began to supply the code structure to me. Prior to that my mind would tell me which book to look for the code structure in. Needless to say, I started picking up speed toward the end.

Keeping it modular

Since my final project for ICM504 is iterative, I needed to put in a lot of thought on how to organize the code so that I could easily tweak and improve further iterations of the project. The code is living in my class notebook right now, but soon I’ll port it over to Flash and see what needs to be tweaked to get the basic structure up and running.  The good news is that it’s definitely ready for modular tweaks. In fact, I remembered as I wrote out the preliminary structure for the First Iteration that online-based projects require front-loaded efforts. I realized that means that the hardest part was what I tackled yesterday afternoon… getting the initial engine up and running.

The coolest thing about ActionScripting for me was that all of my graphics knowledge has made certain things intuitive about the methods and properties that ActionScript uses. (Remember, we’re coding in 2.0, not 3.0 yet… but the new books are aimed at 3.0, so I’m translating backward into 2.0 as I read them).

Look for a code posting and a SWF file link by the end of the week.

First Iteration

The first iteration establishes 9 movie clips on the stage using ‘for’ loops. There are three different colors, red, green, and blue, each with three clips. The clips will populate the screen in random locations. The clips will establish a random target x and y coordinate value. Each frame, the clips will compare their current location against their target location by comparing x and y coordinates. If the comparison results in a match, then the clip will acquire a new random target value. If the current x/y is less than the target x/y, then clip will add the speed value to the current x/y. Or else, it will subtract the speed value from the current x/y. This will be checked for on each frame.

Also on each frame, the clips will make a collision check to see if they hit another movie clip. If a collision is detected, a decision needs to be made on who wins, on the basis of the color of the movieclips involved. The color of the clips ‘R/G/B’ sets up a circular hierarchy, similar in concept to ‘rock/paper/scissors’. If Red and Green hit, then Red will win. If Green and Blue hit, Green will win. If Blue and Red hit, Blue will win. If the two colors are the same, they will result in a tie. The consequence of winning is a speed change. The speed of the winner increases by 1. The speed of the loser decreases by 1, unless speed is already at 0. Hitting a ball of your own color resets the speed of both balls to the starting value again.

I’d like there to be a rebound effect of some sort, though I highly suspect I’ll have to tweak things. After a collision, for now, the rebound will be to ‘teleport’ the lower movie clip in the stack to a random location, to begin again. Because of this, I think that there needs to be a dynamic text field on each of the clips to allow us to track the ‘teleports’.

I expect that the results will be fairly straightforward as far as simulations go. The speed changes add some variability, since it will be possible for a losing streak to end up with several stopped movie clips on the screen. One area I would like to address next would be figuring out some sort of logical result which would seem to obey physics with regards to the rebound angles. The trouble is that I left my physics class in high school right about when we talked about velocity, and with a speed and a distance change… my brain is already shuddering.

// Establish the movie clips on the stage.
Set up a loop to do the following 9 times:
Create an instance of a movie clip and give it a sequential number appended to its name.
Attach that movie clip to the stage by generating a random number (anywhere from 5 px in from each border, (Math.random()*stagewidth/stageheight-10)+5) for _x and for _y.
Initialize that movie clip.

// Initializing the movie clip function
Whatever called upon the Initialize function gets assigned the following:
a number to display in its dynamic text field
a color to display graphically based on the number appended to whatever called upon Initialize (1,4,7 = red, 2,5,8 = green, or 3,6,9 = blue)
a color attribute used for collisions which contains 1 for red, 2 for green, 3 for blue
a targetX and a targetY
an initial speed of 5 pixels per frame

// Motion function
Is targetX > currentX? If so, add speed to this movieclip’s._x position.
Or else, is targetX == to currentX? If so, targetX is random() again.
Otherwise, subtract speed from this movieclip’s._x position.

Is targetY > currentY? If so, add speed to this movieclip’s._y position.
Or else, is targetY == to currentY? If so, targetY is random() again.
Otherwise, subtract speed from this movieclip’s._y position.

// Collision detection function
Check to see if there’s a hit between this movieclip and anything that’s in this movieclip’s space on the parent timeline.
If there is, call upon the hitResolution function.
Otherwise, do nothing.

// hitResolution function
Compare the object that called this function/the one ‘being hit’, with the object that is in that movieclip’s space on the parent timeline.

Check the colorCollision variable.
If this object == that object, both object speeds are set to 5 again.
If this.colorCollision < that.colorCollision OR this-that==2, then add 1 to this.clip’s speed.
If that.colorCollision < this.colorCollision OR that-this==2, then add 1 to that.clip’s speed.

Change direction
If this.level < that.level then that._x/y is assigned to random coordinates,
else this._x/y is assigned to random coordinates.

// The engine to make it go
this.onEnterFrame to make it all run. Every time the frame is loaded after the first time the code runs, each movie clip will do the following things:
detect collisions

That should be it. Tomorrow morning I’ll code it while waiting for the gas company to arrive, and hopefully have test results to talk about.

ActionScripting Final Project

I’m waiting for final approval of my project proposal for ICM504: Information Animation class (better named ActionScript coding ‘101’, IMO), but I want to get started with the basics of the work now. I’m playing around with the concepts of ‘swarming’ behavior of movie clips, as well as the notions of building ‘environmental programming’ or ‘genetic programming’. The digital age equivalent of keeping ant farms, I suppose. The book we’re working from in class, Foundation ActionScript for Flash 8 (2006) by Kristian Besley, Sham Bhangal, and David Powers, with Eric Dolecki is put out by Friends of ED/Apress. One of the exercises in the book dealt with swarm behaviors, and included some thoughts on ways to turn the swarm phenomenon into a ‘simulation’ that mimicked environmental behaviors, etc. Some preliminary searching on the subject showed lots of heavy, high end game theory going on, and lots of advanced programming stuff out there talking about ‘genetic algorithms’ on a pretty heady level.

Not so much as for a “general joe” ActionScript coder and his virtual ant farm. Ah well. This is a ‘101’ level of instruction into ActionScript coding. I have to admit, it’s a lot easier than I thought it was going to be.   Of course, it’s taken the entire course to get us to the point where we can begin to think about projects. There are still basic tricks to learn, but we have enough now to do some pretty cool stuff with Flash and ActionScripting.

The Iterative Project

The final project is going to be an exercise in stretching boundaries for me. It’s also going to allow me to take the baby steps I need in order to actually build up some complex code for Flash. Basically, each day or so I’ll be generating a new iteration. I need to research to find out whether I can post the compiled Flash files on WordPress or if I’ll need to link outside of WordPress. But I will post the code so that folks can follow along at home.

We’ll begin with a statement of purpose for each iteration (e.g. what I’m trying to do differently -this- time), and then I’ll set up the pseudocode writeup, along with any diagrams necessary once the code gets a little more complicated.  I’ve set up a series of benchmarks for success, points that I need to push the code in order to consider myself ‘done’. When I wrote them up, they seemed lofty. When I started thinking about the code itself, they seemed simplistic. When I tried to actually begin -writing- the pseudocode, they seemed difficult again. I think that waffling is a good sign. I’ll accept failure as long as I’ve got a substantial project process built up along the way.

For those who want to read it, here is the pdf of my Final Flash AS 2.0 Project Proposal.

I’ll be starting with the First Iteration today, and I’ll be posting results and documentation as I go. (Apparently no way to link to .swf files directly in WordPress, so I’ll need to find a place  to host them and then link to the other site for the content to appear here in WordPress.)

Interesting Sites and Techs from ActionScripting Class

Yesterday was class 2 for ActionScripting. We covered discussions and review of the previous assignments and then went into some of the professional considerations that are involved in planning, contracting, and scoping an AS development project. We’re using the Foundation ActionScripting for Flash 8 book by Friends Of ED, part of Apress media. Excellent book so far, it seems to spend more time on the ideas surrounding the coding and the professional application of the coding knowledge than just running through the exercises. I recommend it as a good textbook for anyone trying to learn how to code in ActionScripting.

Originally I felt that I didn’t have the required Flash knowledge, but I’m picking up on the interface pretty quickly. Part of any graphics-based software package involves learning how to think in terms of visual problem solving for that particular platform. For example, I work in Photoshop and Illustrator as part of my day job (graphic design and production work for print), and I have for years. When I start in on any design, I’ve got a very structured way of thinking about the final piece or how to construct the final look and feel of things, set out as a series of steps in whichever program I’m using. The vector-based workflow I come up with (for Illustrator) is rather different than the bitmapped-based workflow (for Photoshop).

The same thing needs to happen with Flash. I was worried at first, because this course only deals with the coding aspects of ActionScript, not the design or animation aspects of working in Flash to begin with. The good news is that simply by seeing what kind of things the ActionScript can control and tweak, I’m already beginning to project backward a sense of how I would need to construct an animation sequence in order to make it fit the interface.

When the new 17″ Mac Powerbook Pro arrives, I’ll start messing with Flash animations and seeing how CS3 integrates functionality between Illustrator and Flash. I’ve got a few ideas up my sleeve, but right now I don’t have the portable nature of the new laptop in hand yet. When I do, watch out on several fronts.

Notable Mention: Jitter

In class we started talking about an article by John Simon, Jr. called “Authorship, Creativity, and Code.” I apologize for not having the name of the source book immediately to hand, but here is the author’s website for right now. I’ll edit this post when I find the proper citation. The crux of the essay deals with redefining coding in more creative terms, and it talks about programming languages which are accessable to the artistic mindset. In class I asked about it, and I was referred to a program called Jitter, which is an add-on for a programming platform called MaxMSP.

The idea behind it is that the original programming language involves using a gui instead of lines of code in order to construct workable programming. Jitter expands the original MaxMSP and provides it with customized toolsets for use in ‘programming’ artwork. The only drawback is that it costs $850 for the two, so I won’t be playing with this little language until I’ve had a chance to get a return on my educational investment. In the meanwhile, I’ll start looking through the online materials to see if it’s worth downloading the demo and trying it out.

Fun Site: Gary Skinner’s ‘Gallery Incomplet’

We also spoke about ways that Flash developers are introducing controlled spectrums of “randomness” to various movies and applications. A great example of some of these can be found by noted Flash developer guru Gary Skinner in his online Gallery Incomplet. Enjoy the fun. The ‘tree’ animation grows a differently-shaped tree each time the window is reloaded. Other animations are made to interact with webcam data while simulating free-form flow of graphic elements.

Anyway, as more of these ‘site examples’ get mentioned, I’ll post them here for reference and further enjoyment.

ICM504 – Information Animation, a/k/a “ActionScripting”

Even though this blog has been dominated by my ICM501 Intro coursework so far, I am actually taking other classes. I will be posting about them here as well.

One of the classes which just started last weekend was ICM504: Information Animation, with professor David MacCarella. I admit that I was quite surprised when he told me that we were going to be learning ActionScripting in his class. Actually, ‘surprised’ doesn’t quite cut it. ‘Mortified’ was more the initial reaction, followed by a slight case of ‘awed’. I mean, I just got done with a failed stint as a creative recruiter. I know that ActionScript is one of the ‘advanced’ technologies for the web, and I also know that a designer who can learn it has just doubled their salary for freelance gigs, at any rate.

There’s a little saying I learned when I first took Drawing 101 in Community College. “You don’t take a class for what you already know, you take a class for what you need to learn.” I decided not to stress out about the class, but instead just get right down to business and try by damnedest. I mean, I might not end up with any sort of proficiency in this scripting skillset, but I do know that this is the technology on which much of the future of Rich Internet Application development will be based. I may not need to master it, but I gain much in the way of respect just by understanding the fundamentals of it and being able to communicate with the actual bona fide genius developer-types.

Then again, I don’t give up the hope that I’ll suddenly become a scripter-savant and just take off with the technology. Either way, it’s going to be an interesting class. And I’m just happy to have a class where I don’t need to worry about writing more papers this semester. Although I have to admit — I harbor absolutely no illusions that writing lines of code will be any easier. On the contrary, this is one class where I am going to have to work, and work hard, to make any sort of progress.

We’ll see. More about it as the class develops.