Archive for the ‘flash’ Category

Flash Dynamic Audio Coming Soon

Aug
26

I have been messing with audio in Flash the last couple of days, fresh off the creative high of FITC. I plan in the next couple of days to announce some projects. Stay tuned.

HOWTO Create a Facebook App using FlexBuilder

Jun
24

So for a couple of weeks, I’ve been messing around w/ building a simple app using Facebook. I decided to use the new ActionScript 3 API created by Adobe and Facebook. I wanted to do a little tutorial because some of this information is hard to understand since most of the API has definitions like, ” “.

In this tutorial I will show you how to login to Facebook, retrieve your friends list and populate a TileList with their pictures. Ok, let’s get started.

Read more »

Guitar Synth for Flash

Feb
27

guitarsynth

Andre Michelle has created a guitar synth that sounds AMAZING.

It’s done w/o sampling audio, just math and FP10.

http://lab.andre-michelle.com/karplus-strong-guitar

Abstract Thermometer AIR app

Jan
22

So over the last few months I’ve been messing around with Adobe AIR. The first thing that I worked on was what I was called at the time Abstract Weather Bug. I then noticed that the title was too long.

Look the title is not important. The way the this app works. Is you open the setting slider and enter in your zip, low and high temp scale, Fariehiet or Celsius, and the click GO.

You have the option to save your setting and intervals to which it will check the temperature again.

It then will display a color some were between a gradient of pure blue and red. Post coming soon explaining some of how to create a color scale.

I’m not really a designer (planning to work on that this year) so it doesn’t look awesome.

Roman Numeral/Arabic Convertion AIR App – Johnny V Now Available

Dec
25

Merry Christmas, I got you guys present.

I was looking for a need to make an AIR app, though this isn’t the best one, I turned my converter class into one. Introducing Johnny V.

How to convert Roman Numerals and Arabic numbers in ActionScript 3

Dec
17

This past week I worked on a porting exercise. I have always wanted to find out how you convert Roman Numerals to Arabic numerals and vice versa. So I starting searching and found a bunch of bloated code for converting these numbers then I stumbled on this page.

So in a few hours of screwing around w/ the loops (typing this correctly took a bit) I got it ported. Porting is fun cause all you have to do is translate.

Here is the zip flie and Here is the class.

package com.joshspoon.etc.utils
{
	public class NumberUtils
	{
		public function NumberUtils(){}
 
		public static function romanize(num:int):String {
			var numerals:Array = ["M", "CM", "D", "CD", "C", "XC", "L", "XL", "X",
										"IX", "V", "IV", "I"];
 
			var numbers:Array  = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1];
 
			var lookup:Object = {M:1000,CM:900,D:500,CD:400,C:100,XC:90,L:50,XL:40,X:10,IX:9,V:5,IV:4,I:1}
 
			var roman:String = "";
 
			var i:int;
 
			  for( i = 0; i < numbers.length; i++)
			  {
				while(num >= numbers[i])
				{
					roman += numerals[i];
					num -= numbers[i];
				}
			  }
			  return roman;
			}
 
		public static function deromanize( roman:String ):int {
 
			var numerals:Array = ["I", "V", "X", "L", "C", "D", "M"];
 
			var numbers:Array  = [1, 5, 10, 50, 100, 500, 1000];
 
			var roman:String = roman.toUpperCase();
 
			var arabic:int = 0;
 
			var i:int = roman.length;
 
		    var compare1:int;
			var compare2:int;
 
			while (i--) {
 
		  	var letter:String;
	  		var listLetter:String;
 
		  	for (var j:int = 0; j < = numerals.length - 1; j++)
		  	{
		  		letter = roman.charAt(i);
		  		listLetter = numerals[j];
		  		if(listLetter == letter)
		  		{
		  			compare1 = numbers[j];
		  		}
		  	}
 
		  	for (j = 0; j <= numerals.length - 1; j++)
		  	{
		  		letter = roman.charAt(i + 1);
		  		listLetter = numerals[j];
		  		if(listLetter == letter)
		  		{
		  			compare2 = numbers[j];
		  		}
		  	}
 
		    if (compare1 < compare2 )
		      arabic -= compare1;
		    else
		      arabic += compare1;
		  }
		  return arabic;
		}
 
	}
}

Flash Player 10 Pure Flash Keyboard using SampleDataEvent

Sep
3

Update 10/23/2008

So a bit has changed w/ Flash Player 10 Public Release, I found out that the dynamic sound event changed, again, so I had to make some changes.

Flash Player 10 Public Release Needed

Here is the piano. Once I can build it w/ Air I’ll make it into simple app. I would suggest downloading the swf and running it in your standalone flash player. The keyboard is huge.

I have a couple of ideas to to advance this keyboard:

  1. Decoupling functionality
  2. recording of sound
  3. sustain pedal
  4. pitch ben
  5. modulation
  6. get out an alpha version of the code.

If you have some ideas I’d love to hear them. Please leave me a comment.

Using Flash Player 10 to produce Dynamic Musical Notes

May
20

image of swf flash player 10 guitar tunerSo 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.

View Code:

Read more »

Flash Player 10 Dynamic Sound Generation

May
20

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.

[as]

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));
}
}
}
}

[/as]

Quick and Dirty!

How to load Pixel Bender in Flash Player 10

May
19

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:

[as]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);
}
}
}[/as]

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)) );

}
}