Archive for the 'experiments' Category

Plant Assignment

Friday, September 12th, 2008

Sometimes I’ll give myself programming assignments… these are generally assignments I would give if I were teaching some kind of experimental or visual programming class…. All my classes are currently geared toward more commercial aspects of flash. Anyway, the assignment was… “Take 20 minutes to write a program that draws some kind of plant.”

I started off thinking about doing a recursive function to create branches, but settled on a random walk instead:


Click the above image to see the flash version

I’ve always liked to use sharpen on images - the only problem is that the pixelation around the edges is a little harsh - in the future I may add anti-aliasing to the edges.

Sierpinski Accident

Friday, September 12th, 2008

If your anything like me, you spend your friday nights playing with random code snippets until something interesting appears - or until you pass out. Tonight I was messing with BitmapData in flash and I accidentally stumbled on a weird way to make a Sierpinski Triangle. Try running this on your flash timeline, move your mouse around:

Actionscript:
  1. stage.frameRate = 31;
  2. var canvas:BitmapData = new BitmapData(500,500, true, 0xFF000000);
  3. addChild(new Bitmap(canvas));
  4. var m:Matrix = new Matrix();
  5. m.tx = -1;
  6. addEventListener(Event.ENTER_FRAME, onLoop);
  7. function onLoop(evt:Event):void {
  8.        canvas.setPixel(mouseX, mouseY,0xFFFFFF);
  9.        canvas.copyPixels(canvas, canvas.rect, new Point(1,-1), null, null, true);
  10.        canvas.draw(canvas,m, null, BlendMode.DIFFERENCE);
  11. }

if you run that code, this is what you'll get:

Click the image above to see the flash version.

If you want a triangle that isn't skewed you can just change the matrix tx property and the copyPixels point argument:

Actionscript:
  1. stage.frameRate = 31;
  2. var canvas:BitmapData = new BitmapData(500,500, true, 0xFF000000);
  3. addChild(new Bitmap(canvas));
  4. var m:Matrix = new Matrix();
  5. m.tx = -2;
  6. addEventListener(Event.ENTER_FRAME, onLoop);
  7. function onLoop(evt:Event):void {
  8.        canvas.setPixel(mouseX, mouseY,0xFFFFFF);
  9.        canvas.copyPixels(canvas, canvas.rect, new Point(1,2), null, null, true);
  10.        canvas.draw(canvas,m, null, BlendMode.DIFFERENCE);
  11. }