Monthly Archives: February 2010

Quiz Question

Write code that pulls saturated moving colors from a web cam… that is… if you move a red coffee cup across the screen your code should capture the color red.

A few hints: frame differencing, hsb and get/setVector.

I’ll post my working version tomorrow or the next day… this is a challenging one so I may give an extra day before I post my solution….

Difficulty : Medium

Posted in Quiz | Tagged , , | Leave a comment

Donate Button

I’ve had many requests to add a donate button to this site, finally added one today….

Posted in Uncategorized | Leave a comment

AS Quiz #17

This quiz jumps around a bit from MovieClips to OOP.

Number of Questions : 7
Difficulty : Medium
Topic : MovieClips and OOP

Which of the below is an array of the frame labels in a given MovieClip?





When you manually nest a MovieClip in the Flash IDE, you are then able to use dot syntax to target the nested clip - for instance:

containerClip.nestedClip.play();

This is made possible in part because __________________. (fill in the blank)







True or False... Because MovieClips are dynamic, you can add properties and methods to individual instances of them at runtime.



True or False. The Object class is dynamic.



True or False... In AS3, private constructors are used to create Singletons.



True or False... Using an opening { and a closing } you can define a static initializer within a class.



Fill in the blank... To move forward one frame in a MovieClip you could use the _____________ method.








Posted in Quiz | Tagged , , , | 7 Comments

Prefix Notation (Lisp Style)

Today's quiz is not multiple choice. Instead, your task is to write a lisp style math parser. This may sound tricky, but it's surprisingly simple. (well... not simple exactly, it's just simple compared to what one might assume).

Lisp uses prefix notation... where the operator is placed before the operands:

10 * 10

becomes:

* 10 10

You could think of this as a function "*" with two arguments (10, 10). In Lisp this is enclosed with parens:

(* 10 10)

Let's see a few more examples:

100 / 2 + 10

becomes:

(+ (/ 100 2) 10)

...
2 * 4 * 6 * 7

becomes:

(* 2 4 6 7)

...

(2 + 2) * (10 - 2) * 2

becomes

(* (+ 2 2) (- 10 2) 2)

Remember, thinking "functions" really helps. The above can be though of as:

multiply( add(2, 2), subtract(10 , 2), 2)

You should create a function called parsePrefix() that takes a string and returns a number:

Here is some code to test if your parser works properly:

Actionscript:
  1. trace(parsePrefix("(* 10 10)"));
  2.  
  3. trace(parsePrefix("(* 1 (+ 20 2 (* 2 7) 1) 2)"));
  4.  
  5. trace(parsePrefix("(/ 22 7)"));
  6.  
  7. trace(parsePrefix("(+ (/ 1 1) (/ 1 2) (/ 1 3) (/ 1 4))"));
  8.  
  9. /* Should trace out:
  10. 100
  11. 74
  12. 3.142857142857143
  13. 2.083333333333333
  14. */

I highly recommend giving this a try, it was one of those cases where I assumed it would be much trickier than it was.

I've posted my solution here.

Posted in Math, Quiz | Tagged , , , , | 4 Comments