I started to look into fluid simulation a little while ago.
It turned out that it's not quite as trivial as I had hoped.
That is unless you go for the hacky way as I did back in 2010.
So after getting familiar with the problem and some solutions I implemented a simple fluid simulation
using the canvas element. You can find it in my sandbox.
The plan for the next step is to create a WebGL version.
I hope that the final result will be a worthy successor to the immensely popular (by my standards)
Neon Flames experiment I did last year.
I extracted the simplex noise implementation of my recent voxel experiments into a simple library. You can of course find the source on github. Check out the READ ME or the npm package for more details.
Image error level analysis is a technique that can help to identify manipulations to compressed (JPEG) images by detecting the distribution of error introduced after resaving the image at a specific compression rate. I stumbled across this technique in this presentation by Neal Krawetz and decided to do a quick implementation in JavaScript.
How to use this tool
To analyse an image simply drag and drop it onto the page (requires a modern browser like firefox or chrome).
Then play with the quality slider to spot anomalies in the error level. The image I analyzed in the screenshot above is a picture of myself that I modified in GIMP.
As you can see the error level on the fake part is quite significantly higher than on the rest of the image. There are no such anomalies on the original.
Having that said the algorithm is not exactly reliable, especially with images that have been rescaled and compressed often/intensely. So take it with a pinch of salt and feel free to have a look at the simple source code.
2012-03-02 - updated to use ruby 1.9.3 and official instead of system rvm.
When trying to install ruby 1.9.2 using rvm I got a nasty suprise:
ossl_ssl.c:110:1: error: ‘SSLv2_method’ undeclared here (not in a function)
ossl_ssl.c:111:1: error: ‘SSLv2_server_method’ undeclared here (not in a function)
ossl_ssl.c:112:1: error: ‘SSLv2_client_method’ undeclared here (not in a function)
make[1]: *** [ossl_ssl.o] Error 1
make[1]: Leaving directory `/var/cache/ruby-rvm/src/ruby-1.9.2-p180/ext/openssl'
make: *** [mkmain.sh] Error 1
The solution
# install rvm
bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer )# make sure we have $rvm_pathsource /etc/profile
# don't use ubuntus openssl
rvm pkg install openssl
rvm install 1.9.3-p125 --with-openssl-dir=$rvm_path/usr
I generally like dynamic languages and in generally don't run into much trouble with them.
Having that said, I hate the way undefined and NaN work in Javascript.
This turns a simple typo into a NaN apocalypse. After half of your numbers have turned into NaNs
it's hard to find out where they came from.
varo={y:0},#NaN1/o;#NaNvarx=1/o.x;#NaNvary=x*10;
Setting up traps
So how do you catch stray NaNs? You set up traps. Because it can become very tedious and error prone to have
asserts everywhere I wrote a little helper, fuckNaN().
functionfuckNaN(obj,name){varkey='__'+name;obj.__defineGetter__(name,function(){returnthis[key];});obj.__defineSetter__(name,function(v){// you can also check for isFinite() in here if you'd like toif(typeofv!=='number'||isNaN(v)){thrownewTypeError(name+' isNaN');}this[key]=v;});}// Examplesvaro={x:0};fuckNaN(o,'x');// throws TypeError: x isNaNo.x=1/undefined;// Also works with prototypesfunctionO(){this.x=0;}fuckNaN(O.prototype,'x');varo=newO();// throws TypeError: x isNaNo.x=1/undefined;
Place some of those traps during debug mode in critical locations like your Vector and Matrix classes and they will bring doom and destruction to those NaNs..
Note: This doesn't work in IE<=8 and you shouldn't use it in production. Use it as a tool during development to make your code fail early.
As some of you know I work for local.ch. I was looking for cool visualizations to do with
our data for quite a while, missing the obvious - plotting all our 3.7 million geocoded addresses in 3D using WebGL!
I'm actually quite impressed by the accuracy of the data. But go and have a look for your self.
Controls
WASD + Mouse (drag). Velocity is scaled with altitude.
Video
If you can't see the demo for some reason I uploaded a short video of the demo to youtube.
Techniques
The points are encoded in a Float32Array, then sorted and gziped using a python script. Sorting the data improves the compression ratio by over 200% so it's well worth the effort. This brings the original 100mb file down to 7mb.
The file is then loaded using XHR level 2,
which supports binary files and progress events. The points are then rendered using WebGL as GL_POINTS and additive blending is
used to give it a glow effect. In the future I might add HDR rendering and blooming.
There is no level of detail or culling performed so this will require a relatively powerful rig.
Also note that for some reason Firefox Aurora (9) seems to be quicker than Chrome Dev (16) for some mysterious reason.
I would expect all of the work to be done by OpenGL so I'm not sure about where this comes from. It could be chromes
process isolation.
Sourcecode
You can find the source code on github if you want to get into some hacking.
Note that the data belongs to local.ch and may not be used.
Some of you might remember my Chaotic Particles demo from last year. That demo was featuring 10'000 particles on a plain old 2d canvas. I decided to optimize that demo a bit in order to support 100'000 particles. I also fixed a little issue where numeric inaccuracy allowed particles to escape and made the influence map more fine grained.
Want to see the source? Just use view source and feel free to ask questions.
I think this is my favorite canvas demo I have created so far. It is an interactive drawing tool based on particle effects. It is the result of me trying to create some generative art using canvas. The techniques used
are actually pretty similar to the ones shown in my frontendconf talk on particle systems. In short:
I'm planning to play with a few improvements especially in tone mapping and controls in the future but feel free to take a look at the source on github. I hope you enjoy it.
I finally finished my first WebGL demo. Try it and let me know how you like it.
Sourcecode
You can find the source code on github if you want to get into some hacking.
Compatibility
To run the demo you'll need a browser that supports webgl and the OES_TEXTURE_FLOAT extension. At the moment this means Google Chrome 12 or Firefox Aurora (6.0a2). The extension is needed for HDR rendering.