Posts Tagged 'wonderfl'



Matching colors in RGB

I decided that this blog needs another post, preferably on subject with some real applications. Unlike my Mandelbrot log-map experiments or allRGB mini “game”. Because why would anyone read about those boring  useless things… And, since I am cooking real application here that tracks real colored blobs, the subject today will be color matching.

If you have been searching for this stuff before ending up here, you could notice that cool guys never do color matching in RGB, but instead go with HSV or similar hue-based color space. The idea here is, probably, that when you pull all color information into one coordinate, you can forget about other two. Unfortunately you can’t :( It’s not to say that there is some kind of a problem here, not at all. With tools like pixel bender on your belt, you just write a shader that converts to HSV and applies thresholds in one breath, and voila – you get your blobs to track. But, for some reason, this kind of blind belief in hue dogma just doesn’t sit well with me.

Continue reading ‘Matching colors in RGB’

Solving polynomials, complex arithmetics and code inlining

Yeah, this is what I’ve been doing in my spare time these last days. Basically, I needed to find all roots of 4th power polynomial and, after quick search, I’ve found great wiki article on new Durand-Kerner method that makes Newton-Raphson look outdated: using only simple arithmetics it simultaneously finds all polynomial roots no matter how wrong your initial guess is. The only problem is that it needs complex numbers.

So, I had to implement complex numbers in some way. Obviously, since AS3 does not support operator overloading, we end up with a bunch of function calls. The problem here is that even these short formulas require quite a lot of them, and you need to keep evaluating that over and over before solution is found, which, as you might guess, is not so CPU-friendly. So I decided to inline them all. To this end, I downloaded and installed apparat by Joa Ebert. This actually went much easier than I expected, the only problem I ran into was that it does not work with current version of scala. Any way, getting your code inlined with this tool is as easy as extending special class. However, checking my resulting SWF with AS3 decompiler, I have found that apparat does not remove neither its own nor my custom classes which were inlined and so are no longer used anywhere. Since this is not something Joa would be willing to fix, I turned to GPP, a tool pre-processing macros in source rather than post-processing bytecode in SWF. As a result of these adventures, I have these two FlashDevelop projects for grabs in svn (view).

The other problem with complex numbers implementation in AS3 is readability. Endless lines of similar function calls separated by semicolons look pretty much like some old code in asm, if you ever seen one. In order to somewhat ease the pain, I decided to at least make it possible to chain function calls into formulas. This normally implies another performance penalty because you need to create new temporary variables in the process; however, it can be avoided by pooling those variables. This implementation can be found (and forked :) at wonderfl.

Well, that’s it for today, I’m off to enjoy my sunday.

Inverse homography using drawTriangles()

Flash player version 10+ native drawTriangles() method is perfect for programming homography (2D transformation that preserves lines) because of its support for UVT data. In general case, however, homography requires solving 8×8 linear equations system, so noone can be arsed to code that. Instead they implement one of two special cases – mapping rectangle to or from quadrilateral. So far, only 1st case was implemented using drawTriangles, while 2nd case was done using filters. Well, no longer so – it turned out, inverting T values in Zeh code was sufficient to make it work backwards:

One interesting thing about this code is that noone really knows exactly how it works :) I didn’t have to study all the math behind Zeh code in order to “invert” it, and Zeh… well, let me quote:

I was lucky enough to get what I wanted working after a good amount of crazy trial and error (and beer)

Improving marching squares

Right. Today is the day of improving 2×2 marching squares flavor described in wikipedia. A year ago Sakri Rosenstrom found that it is flawed:

As you can see, two checkerboard-like patterns are ambiguous, but the algorithm ignores it, causing random deadlocks as a side effect. So I tried to find some solution to this by posting the problem at wonderfl; and then I just couldn’t wait :) Well, my solution uses 2 to 4 pixels out of 2×2 window and seems to work on crazy images, so I’m happy. But if you suddenly find some better way, let me know.

Tween capture

Tweener may be dead, but people are still posting to its mailing list. This time someone posted an idea so awesome that I could not resist to try it :)

Midnight Brainfuck

Did you ever tried to imagine what would rotation of impossible rectangle look like? Well, these guys did but, with all due respect, their results are ugly. I thought I could do better than that, so tonight I made this:

(click it to go to my wonderfl code)

CSI zoom to my house

Some days ago I was thinking how to make deep Mandelbrot zoom to run in real time. We already have shallow low-res zooms running in real time, but deep zooms require more and more iterations per pixel, so unfortunately our only way to work around this seems to be to precompute zoom in some way, and then make whole thing to appear as if it was running in real time, i.e. make it interactive. Obvious way to do this would be to seek in zoom video, but what’s the fun in that? Instead, I was looking for some way to zoom in single image, CSI style. Continue reading ‘CSI zoom to my house’


Old stuff

September 2014
M T W T F S S
« Aug    
1234567
891011121314
15161718192021
22232425262728
2930  

Follow

Get every new post delivered to your Inbox.