June 20, 2008
May 22, 2008
Thanks to Alex Bustin. He decided to take the bandwidth hit and upload the Flash Player 10 API to his site.
No you don’t have to download it. Also, Matt Chotin said that some new properties do not code complete currently, so don’t think you did something wrong. It’s Adobe not you.
So after 13 year of off and on drumming I have learned a thing or two about music. Not much about tuning a guitar. Thanks to a class that I got a D in, Musical Acoustics, I know every note produces a frequency and a wavelength. With that you can now you Flash to produce a frequency and that is what I did, the six notes from left to right are the notes of a regularly tuned guitar.
Since I lost my Musical Acoustics book from UNT I had to look it up to find the Frequency of All Notes
and that pick the ones I wanted starting w/ E4.
So if you don’t have a guitar tuner…here you go.
To view this you will need Flash Player 10
View Code:
I miss writing classes w/ 50 or so lines of code and here is one. This is a take off of Lee Brimelow's Example of Dynamic Sound Generation. I'm using the BitmapData to create a tone.
-
package
-
{
-
import flash.display.*;
-
import flash.events.*;
-
import flash.media.*;
-
import flash.net.URLRequest;
-
import flash.system.Capabilities;
-
import flash.text.TextField;
-
-
public class DynamicSound extends Sprite
-
{
-
private var sound:Sound;
-
private var noise:Number = 0;
-
private var _loader:Loader;
-
private var _bm:Bitmap;
-
private var _verText:TextField;
-
public function DynamicSound():void
-
{
-
stage.align = StageAlign.TOP_LEFT;
-
stage.scaleMode = StageScaleMode.NO_SCALE;
-
_verText = new TextField();
-
_verText.text = Capabilities.playerType + " (" + Capabilities.version + ")";
-
_loader = new Loader();
-
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete, false, 0, true);
-
_loader.load(new URLRequest("http://www.scarlet.nl/~ivo/photo_ASTRO3.JPEG"));
-
-
}
-
-
private function onComplete(evt:Event):void
-
{
-
_bm = Bitmap(_loader.content);
-
addChild(_bm);
-
addChild(_verText);
-
sound = new Sound();
-
sound.addEventListener(Event.SAMPLES_CALLBACK, onCallback);
-
sound.play();
-
}
-
private function onCallback(e:SamplesCallbackEvent):void
-
{
-
for(var i:uint=0; i<512; i++)
-
{
-
noise += _bm.bitmapData.getPixel(mouseX, mouseY)/ 44100;
-
var sample:Number = noise * Math.PI * 2;
-
sound.samplesCallbackData.writeFloat(Math.sin(sample));
-
-
sound.samplesCallbackData.writeFloat(Math.sin(sample));
-
}
-
}
-
}
-
}
Quick and Dirty!
May 19, 2008
Hey so I spent most of the weekend trying to get Senocular's tutorial on loading .pbj into flash player 10.
For some reason it wasn't working for me so I decided to download Pixel Bender Preview Release and copy the file's source code and export it (File > Export Pixel Bender...for Flash) and it worked so I wanted to post it. Just in case some one had the same problem.
AS FILE:
-
package {
-
import flash.display.*;
-
import flash.events.*;
-
import flash.net.URLLoader;
-
import flash.net.URLLoaderDataFormat;
-
import flash.net.URLRequest;
-
import flash.utils.ByteArray;
-
import flash.utils.getTimer;
-
-
public class astro2 extends Sprite
-
{
-
-
// image for shader fill
-
private var _bitmap:Bitmap;
-
-
// shader fill shader; it will use
-
// the image as an input
-
private var _shader:Shader;
-
-
// loader to load pixel bender bytecode
-
// for shader instance
-
private var _shaderLoader:URLLoader
-
-
private var _loader:Loader
-
-
public function astro2()
-
{
-
//load image
-
stage.align = StageAlign.TOP_LEFT;
-
stage.scaleMode = StageScaleMode.NO_SCALE;
-
_loader = new Loader();
-
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onImgLoad, false, 0, true);
-
_loader.load(new URLRequest("http://bp2.blogger.com/_Y8m29ZLX5ag/RarR3rcAVwI/AAAAAAAAAL4/dtA7xOMrI4g/s400/ASTRO_jpg.jpg"));
-
-
}
-
-
//once loaded load Pixel Bender File
-
private function onImgLoad(evt:Event):void
-
{
-
_bitmap = Bitmap(_loader.content);
-
-
_shader = new Shader();
-
_shaderLoader = new URLLoader();
-
-
_shaderLoader.dataFormat = URLLoaderDataFormat.BINARY;
-
_shaderLoader.addEventListener(Event.COMPLETE, shaderLoaded);
-
_shaderLoader.load(new URLRequest("test.pbj"));
-
}
-
-
// shaderLoader complete handler
-
private function shaderLoaded(event:Event):void {
-
-
// set up shader
-
-
_shader.byteCode = _shaderLoader.data as ByteArray; // error if invalid
-
_shader.data.src.input = _bitmap.bitmapData; // image input
-
_shader.data.size.value = [100]; // constant size
-
_shader.data.fade.value = [.5]; // constant fade value
-
-
// draw the shader every frame
-
addEventListener(Event.ENTER_FRAME, drawKaleidoscope);
-
-
}
-
-
// enterframe handler
-
private function drawKaleidoscope(event:Event):void {
-
// base position on mouse location
-
_shader.data.position.value = [mouseX, mouseY];
-
// rotate constantly over time
-
_shader.data.angle.value = [getTimer()/500];
-
-
// draw a rectangle with the shader fill
-
graphics.clear();
-
graphics.beginShaderFill(_shader);
-
graphics.drawRect(0,0,300,250);
-
}
-
}
-
}
and the Pixel Bender code:
kernel Kaleidoscope
< namespace : "Petri Leskinen";
version : 1;
vendor : "";
description : "kaleidoscope -effect, rectangular";
>
{
parameter float4 fadeColor
<
minValue: float4(0,0,0,0);
maxValue: float4(1,1,1,1);
defaultValue: float4(0,0,0,1);
description: "Fade color";
>;
parameter float2 position
<
minValue: float2(0,0);
maxValue: float2(2880,2880);
defaultValue: float2(250,280);
description: "Center point";
>;
parameter float size
<
minValue: float(1);
maxValue: float(500);
defaultValue: float(75);
description: "Size";
>;
parameter float fade
<
minValue: float(0.5);
maxValue: float(1.0);
defaultValue: float(1.0);
description: "Fade";
>;
parameter float angle
<
minValue: float(-3.14159);
maxValue: float(3.14159);
defaultValue: float(0.5);
description: "Rotation angle";
>;
input image4 src;
output pixel4 dst;
void evaluatePixel()
{
float sina = sin(angle);
float cosa = cos(angle);
float2 newC = position - size/2.0* float2(cosa+sina, cosa-sina);
// mx matrix for rotation and scaling
// mxR reverse transformation
float2x2 mx = float2x2( cosa,sina,-sina,cosa) /size;
float2x2 mxR = float2x2( cosa,-sina,sina,cosa) *size;
// coordinate p1 on the new coordinate system,
// on the center area 0.0 < p1.x < 1.0 , 0.0 < p1.y < 1.0
float2 p1 = mx * (outCoord() -newC);
// p2 integer part, p1 only decimal part,
// which maps every pixel to the center area
float2 p2 = floor(p1);
p1 = fract(p1); // p1 -= p2;
// p3 dislocation for mirroring,
// mirrored if integer part odd
float2 p3 = 1.0-2.0*p1;
p1.x += mod (p2.x,2.0) > 0.0 ? p3.x : 0.0 ;
p1.y += mod (p2.y,2.0) > 0.0 ? p3.y : 0.0 ;
// reverting to the main coordinate system, sampling and mixing the pixel
p1 = newC + mxR*p1;
dst = mix( fadeColor, sampleLinear(src,p1) ,
pow ( fade,abs(p2.x)+abs(p2.y)) );
}
}
As many of you know ASTRO is in Public beta.
Here are some links on how to compile:
Text instruction - by Mike Chanmbers
Video Instruction - by Lee Brimelow
A promising sound example:
flash produced sound example - by Keith Peters
Here is my "3D" example, quick and dirty:
-
package {
-
import flash.display.Loader;
-
import flash.display.MovieClip;
-
import flash.display.Sprite;
-
import flash.display.StageAlign;
-
import flash.display.StageScaleMode;
-
import flash.events.Event;
-
import flash.events.MouseEvent;
-
import flash.geom.Vector3D;
-
import flash.net.URLRequest;
-
-
public class ASTRO extends Sprite
-
{
-
-
private var _loader:Loader;
-
private var mc:MovieClip;
-
public function ASTRO()
-
{
-
-
stage.align = StageAlign.TOP_LEFT;
-
stage.scaleMode = StageScaleMode.EXACT_FIT;
-
_loader = new Loader()
-
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete, false, 0, true);
-
_loader.load(new URLRequest("record.gif"));
-
-
}
-
-
private function loadComplete(evt:Event):void
-
{
-
-
mc = new MovieClip();
-
mc.rotationY = 0;
-
mc.rotationZ = 0;
-
-
stage.addEventListener(MouseEvent.MOUSE_MOVE, onMove, false, 0, true);
-
mc.opaqueBackground = true;
-
_loader.x = - (_loader.width * 0.5);
-
_loader.y = - (_loader.height * 0.5);
-
mc.addChild(_loader);
-
mc.x = (_loader.width * 0.5);
-
mc.y = (_loader.height * 0.5);
-
addChild(mc);
-
-
}
-
-
private function onMove(evt:MouseEvent):void
-
{
-
mc.rotationZ = stage.mouseY;
-
mc.rotationX = stage.mouseX
-
-
}
-
}
-
}
Also here are some classes that I saw through code completion. I don't really know what to do with them yet. Maybe someone else will and will let me know (I have too much work and GTAing to do
).
- flash.text.engine Package (over a dozen classes)
- __AS3__.vec.Vector (that is wierd)
- flash.display.GraphicsBitmapFill
- flash.display.GraphicsPathCommand
- flash.display.TriangleCulling (that sounds interesting)
- flash.geom.Vector3D
- flash.filters.ShaderFilter
Happy Coding!
April 29, 2008
Alright, this example is very similar to the other examples I have done. But with this one I am scaling all pixels at the same rate. Just click on it the image in the example (more...)
April 23, 2008

Alright, in this example, I am cutting each pixel in an image and piecing it back together again. Only this time I animating the pixel to a new location, piecing back the image at 200%. I think this can open a lot doors in what you can do with a bitmap. (more...)
April 21, 2008
So the last couple of weeks I have been jacking around w/ Bitmaps and BitmapData. I've always wanted to try it but never had the courage. Now that I have, I wish I'd have done it sooner.
In this first example I'm just copying each pixel throwing it to the wind and using Tweener to animate it to a spot. I don't think Tweener is the best option course as you can see it runs slow. I'm also using Grant Skinner's Memory Gauge to illustrate how slow it is. This is just a proof of concept anyway.
April 15, 2008
So today Daniel Dura, an Adobe Evangelist, came by Travelocity to talk about Flash, Flex and AIR. It was interesting to here him speak and his hair was redder then pictures led on. But I won't hold that against him. (more...)

Josh Weatherspoon, A self-proclaimed millionaire who for some reason has to work as a Flash Developer, at Travelocity in Dallas(Southlake), TX.

