Drawing using controlpoints

There is an old trick which comes down to drawing a fluid line through controlpoints, by using the average of the controlpoints as anchors.

Here is my quick and dirty go at it:



You can download the example here: ControlPointDrawing (392)

arguments.callee._name in ActionScript 2

A question on the flashcoders list about an hour ago triggered me to put together a very simple example that I have been wanting to put together for ages now.

How do you get the name of a function?

With function we could refer to:

  • any function
  • a calling function
  • a function being called

My reflection package is at the core of my xflas2 logger. It provides much the same information MTASC can put into a trace statement WITHOUT MTASC (except for the linenumbers).

Anyway, the reflection package is perfectly capable of being used standalone without a logger of some kind. It provides two simple classes with an even simpler API: ClassFinder and FunctionFinder.

Imagine a function:

	
	private static function runExample3() {
		_print (
			"I am :"+
			FunctionFinder.getFunctionName(arguments.callee)+
			" and I am defined in "+
			ClassFinder.getClassName(
				FunctionFinder.getFunctionClass(arguments.callee)
			)+
			" and was called by "+
			FunctionFinder.getFunctionName(arguments.caller)				
		);
	}

Note that it’s static, but it doesn’t have to be, I’m just being a lazy git.

This prints:


I am :runExample3 and I am defined in SampleClass and I was called by main

Now, for the small print : you HAVE to call ClassFinder.registerAll() once somewhere at the start of your program.

Download the sample here: GettingCalleeName (517)

AsSetPropFlags Explained

You might stop reading here, everything you need to know is in the provided example:AssetpropsflagsExample (450).

So you have decided to read on. Yes, it’s 2007 & I’m still doing AS2. I know, it’s sad, and I’m never gonna get my band started (weird purple tentacle sucking noises). But believe or not, I still love it :).
One of the things on my todo list was understanding the AsSetPropsFlags demon. As with all things, once you do understand them, you can’t understand why it took you so long.

AsSetPropFlags is simple. Really. Assuming you know your binary numbers, and I assume you do. But if you don’t check the example below and the utility classes provided.

So now I’m going to try and explain it to you :). Note that I only have used it in Flash 7 and above, so don’t ask me about all the flash 5 and flash 6 weirdness involved.

Read more

Image flipping

A post on the flashcoderlist (http://www.mail-archive.com/flashcoders@chattyfig.figleaf.com/msg34296.html) asking about an image turn around effect got me coding for 2 hours in a row until I finished it and realized my effect was not quite similar to what was required (http://www.ja-ik-doe-mee.be/).

Anyway I liked it nonetheless so posting it anyway.

You can download this example here (Flash IDE & FlashDevelop / MTASC compatible):ImageTurnEffect (900).

Calculating displacement maps based on reference maps

I already blogged about this, but I saw that some items could use some more explanation. Please read “Getting the displacement you need” first for the basic idea.

In short the principle is:

  • you have a reference map, say A
  • you apply a distortion effect to the reference map created a distorted version of A say A’
  • you calculate the displacement map that could transform A into A’ by calculating the difference in pixel value between A and A’

Difference process

Some important points before we start:
Read more

Panoramic projection using displacement mapping

In this post we will be looking at the creation of a distorted panorama using a displacement map. The two examples below show the difference between a panorama without and with distortion (notice how in the distorted version the grid bends):

Panorama without distortion (NondistortedPanorama (466))

Panorama with distortion (Distorted Panorama (557))

Some simple tricks to note up front: Read more

Getting the displacement you need in ActionScript 2

In my previous post I explained the basics of displacement mapping, and I promised to tell something about getting the filter to do what you want it to do. Well, in order to do so, let’s look at the picture I showed you again, written a little differently:

+ *? =

where ? is an unknown scale factor

It says that given a source image, if we apply a displacement map multiplied by some scaling factor, we will end up with a result image. If we look at the visual formula written like this:

ImgSource + DispMap*ScaleFactor = ImgResult,

we can see that with some basic math we get:

ImgResult – ImgSource = DispMap*ScaleFactor, in other words:

= *?

This tells us that if we have the source image and the result, that we can in theory calculate the displacement map, but since the displacement map is related to the scalefactor, there is not a single result.

Would this simple idea gives us the one possible displacement map that caused the transformation of ImgSource into ImgResult?

Read more

Displacement maps pt. 1 Basics

I was working on the Bitmap API and the Displacement map filter and although there was some info available on it, it takes some time to get it to do what you want.

Basically a Displacement map is a BitmapFilter, in other words: it moves around pixels.

If you would take a source image and apply a transform to each pixel from the viewpoint of the source image, pixels might end up all over the place and some pixels in the destination image might remain unset. This is usually the way we think about transformations though: we have a source, we apply a transform and get something new.
Read more