As I said, it’s really simple, it’s not the best code but it gives you some ideas of how it’s made.
Inside the “tags” folder, I have three pngs for each shape (triangle, square and circle).
You draw the shape you want, I trim it, and compare to each png.
The comparisson is, get the drawn image, stretch it to the size of each png, and apply threshold. The BitmapData.threshold returns you an uint, the number of pixels that has been changed. With this number, divide it to the area of the png, and than, you choose the one that returns you tha smallest number.
and… that’s it. simple simple…
actually, it’s a technique used for some facial/object recognition softwares, but in a simplified way.
Well, I went to the Flash On The Beach for the first time this year. Was really cool and inspiring.
The first night, I had some inspiration, nothing to deal to any of the presentations I saw, but just something that I wanted to test. I couldn’t upload it because I didn’t have internet at the hotel, and at the venue the firewall was blocking me to connect to my FTP.
So, what was my experiment this time?
Gesture!
I think it’s working quite nice for a code I took less than an hour to write. It was much easier than I thought.
Just click and try to draw a Triangle, Circle or Square.
And the source files zipped with the demos I showed.
http://www.hellokeita.in/presentations/LFPUG/20090827/examples.zip
The contents are:
Example01-SineWaveExample: Simple example generating a sine wave
Example02-KeyboardExample: Example of a piano keyboard
Example03-WaveformExample: Changing the waveform of a sound
Example04-TimePitchExample: Changing pitch and tempo of a mp3
Example05-HeliumBalloon: Real time pitch shifting using Java
Yesterday was my very first time presenting in English at LFPUG.
I was quite nervous but everything went really well.
Thanks Tink to letting me speak there.
Thank you for everyone that went there. The applause in the middle of the presentation cheered me up.
I really enjoyed speaking, and I hope there’s a next time.
I’ll prepare a PDF of the presentation I did together with the source code of the demos I showed and post it here.
Also, Tink should upload the recorded video of the presentation in few days on LFPUG website http://www.lfpug.com
Pitch shifting is the method to change the frequency or the height of a sound.
And why it’s fake? Because, I’m really not using the correct algorithm, actually I just made one for demo purpose. If you listen carefully, you can hear some clippings when you change the slider position.
There is a difference between my previous post about pitch Controlling Pitch and Tempo.
The previous one I was using a dynamically generated sine wave and changing the pitch. It’s much easier because I already have the samples for each sound.
On this example I’m using an MP3 file (Daft Punk, please don’t sue me…If you want, I can change it) and changing the pitch on runtime.
Well it’s working, and as you can see no FPS loss.
The source… well, I’m preparing for my LFPUG presentation so, I’ll try to explain about it there, and than release some kind of source.
There is a post from my friend Li http://www.lidev.com.ar/?p=237 where he is using more accurate algorithm to change the pitch. There’s not much loss on quality and no clips.
Komposer is the main class, who will playback the music.
Timbre is the class that defines the tone of the sound.
Track is a groups of notes that will play with the defined timbre. Currently it will only play one track.
Note is the class that defines the pitch(frequency) and the in/out of the sound.
var komposer:Komposer = new Komposer();
var timbre:Timbre = new Timbre();
timbre.addValue(0);
timbre.addValue(1);
timbre.addValue(-1);
timbre.addValue(0);
March 21, 2009 at 3:46 am
· Filed under AIR, AS3, source
I just found out something cool using URLRequestHeaders in AIR.
Using the “Range” header, you can download specific part of a file.
var urlLoader:URLLoader = new URLLoader();
var urlRequest:URLRequest = new URLRequest("http://upload.wikimedia.org/wikipedia/commons/f/f2/Fanciful_Landscape-1834-Thomas_Doughty.jpg");
urlRequest.method = "GET";
urlRequest.requestHeaders = [new URLRequestHeader("Range", "bytes=0-99")];
urlLoader.addEventListener(Event.COMPLETE, loaded);
urlLoader.load(urlRequest);
function loaded(e:Event):void{
trace(e.currentTarget.data);
}
In this example above, it will load just the first 100 bytes of the file.
I don’t know if there is other ways to do it, but, at least it worked fine for me.
With this, you can manage downloads for huge files pausing and resuming not loosing datas.
Like, if the internet connection breaks while you are downloading something, you can simply resume after the internet connection comes back.
It’s a small class br.hellokeita.utils.MathUtils.
Inside, there are few methods: combination, factorial, solveCramer and squareMatrixDeterminant.
I think method name tells what it does, so please check it out and comment about it.
Basically, the curveTo method uses a quadratic bézier, so you need a control point and a anchor point.
But it’s difficult to find the precise control point for a curve you want, because the control point is not inside the curve.
Also, you just can create a curve with just one control point, or if you want to use many curveTo methods in sequence, sometimes the curve doesn’t became as straight as you want.
So, I created a class that calculates the control points with multiple values bézier.
You can also get the position in this curve.
Here goes the examples. (you can click and drag the points)
This is an example using 7 positions, the start and the end anchors and 5 control points.
In the class, there’s a method that returns me an array with the approximated quadratic bézier values, so I’m using this values to draw the green line.
You see that it still hard to draw a path that you want.
This is the same example, but now the positions are inset in the curve.
Now, it became easier to create a curve line.
And here, a animation over the curve.
Sorry for lack of explanation, actually I’m in vacation now, but I wanted to post this class.
Later I’ll try to post more examples and uses.
I will try to update my svn with these classes, commented, after I came back from vacation.
So, for now, here is the source code.