var circle:Shape = Shape(addChild(new Shape));
with(circle.graphics) beginFill(0x000000), drawCircle(0,0,5);
var bezierPoint:Point = new Point();
function bezier(a:Number, x1:Number, y1:Number, x2:Number, y2:Number, x3:Number, y3:Number):void {
var b:Number =1-a;
var pre1:Number=a*a;
var pre2:Number=2*a*b;
var pre3:Number=b*b;
bezierPoint.x = pre1*x1 + pre2*x2 + pre3*x3;
bezierPoint.y = pre1*y1 + pre2*y2 + pre3*y3;
}
var inc:Number = 0;
var theta:Number = 0;
addEventListener(Event.ENTER_FRAME, onLoop);
function onLoop(evt:Event):void {
graphics.clear();
graphics.lineStyle(0,0xFF0000);
graphics.moveTo(200,200);
graphics.curveTo(mouseX, mouseY, 400, 200);
theta+= .05;
inc = .5 + .5*Math.sin(theta);
bezier(inc, 200, 200, mouseX, mouseY, 400, 200);
circle.x = bezierPoint.x;
circle.y = bezierPoint.y;
}
The above animates a circle along a quadratic bezier curve. This snippet was written in response to a question spurned by some of the recent bezier posts. I used Math.sin() to animate the circle but you could just as easily use modulus… simply replace lines 25-26 with the following:
I learned how seamless tiles worked by observing the KPT seamless welder filter while I was in highschool. I wish I could dig up all that old KPT stuff again….
There are better seamless tile algorithms out there…. this one is very primitive, but it will work nicely if used properly. Could work well with a composite texture in Papervision 3D for instance…
Mario Klingemann is the developer of Peacock… an excellent node based image generator written in ActionScript.
BitmapData.paletteMap() is very powerful. I haven’t done much with it, but I have some ideas floating around.
For those of you that are game of live savvy… try other rule sets from the lexicon… my personal favorite has always been coral (45678/3). Here’s a link to some more.
Another short game of life recently appeared on on the 25lines.com forums…. here… the forum post features a nice explanation for using a ConvolutionFilter and Threshold to create The Game of Life. The technique is so small and impressive looking that I figured I’d post it as is right here:
addChild(new Bitmap(new BitmapData(stage.stageWidth, stage.stageHeight, false, 0)))["bitmapData"].noise(int(Math.random()*int.MAX_VALUE),0,255,7,true);
addEventListener(Event.ENTER_FRAME, function (e) {
getChildAt(0)["bitmapData"].applyFilter(getChildAt(0)["bitmapData"], getChildAt(0)["bitmapData"].rect, new Point(), new ConvolutionFilter(3, 3, [3,3,3,3,2,3,3,3,3],255,0,true,false,0,1));
getChildAt(0)["bitmapData"].threshold(getChildAt(0)["bitmapData"], getChildAt(0)["bitmapData"].rect, new Point(), "==", 8, 0xFFFFFFFF, 0xFC);
getChildAt(0)["bitmapData"].threshold(getChildAt(0)["bitmapData"], getChildAt(0)["bitmapData"].rect, new Point(), "!=", 0xFFFFFFFF, 0x00000000)})
The above code is by Daniil Tutubalin 25lines.com forums.
UPDATE:
Since writing this post the 25lines.com forum thread has grown to include a 4 line version and some additional discussion about this topic… be sure to check it out.
I think displacement maps are underused – they’re very powerful. In this snippet I use a DisplacementMapFilter to create a parallax effect on some perlin noise and a radial gradient. The result is an abstract texture that looks 3D.
I got the idea from a demo for the alternative game engine. The first time I saw this demo I had no idea how they were doing it… but after looking at it a few times, I noticed some distortion around the neck area of the model… at that point I recognized it as a displacement map and whipped up a demo (using a drawings as the source image). The alternativa demo also has some color stuff happening to simulate lighting… I’m assuming that’s done with a ColorMatrixFilter or two, but I’m not sure.
As in the alternativa demo, this technique could be used with 2 images… one depth map rendered out from your favorite 3D app and one textured render….