PDA

View Full Version : [ voronoi based image filter ]



pwdVergesser
August 25th, 2008, 07:49 AM
Hi,

a few days ago I posted my first image processor experiment, based on delaunay triangulations (http://www.kirupa.com/forum/showthread.php?t=306618). now, my second release is done, and this time Iīve played around with voronoi diagrams.

http://www.dasprinzip.com/pExamples/p70_0.jpg
Launch (http://www.dasprinzip.com/prinzipiell/2008/08/25/voronoi-tesselations/).

The whole thing runs on my computer mostly by having up to ~24fps constantly.


Cheers
pwd

prototype
August 25th, 2008, 10:10 AM
That's very unique!

Source?

ChromeDemon
August 25th, 2008, 11:38 AM
Cool stuff as usual ...
How about sum Sources for the rest ???

bootiteq
August 25th, 2008, 01:47 PM
Very nice

sekasi
August 25th, 2008, 06:22 PM
Nice work as to be expected of you bud. It's interesting, because I was fumbling with the same filter effect just a few days ago but couldn't get the code anywhere near as optimized as yours. I must've started in the wrong end or something.

This gives me sum inspiration to redo it though;) thanks!

matthewjumps
August 26th, 2008, 12:06 AM
thats funky!

pwdVergesser
August 26th, 2008, 03:49 AM
That's very unique!

Source?


Cool stuff as usual ...
How about sum Sources for the rest ???

...I will post the sources when the whole filter collection is ready. Promised!



Nice work as to be expected of you bud. It's interesting, because I was fumbling with the same filter effect just a few days ago but couldn't get the code anywhere near as optimized as yours. I must've started in the wrong end or something.

This gives me sum inspiration to redo it though;) thanks!

...thx, but itīs a mess to see that the limit of my snippet is up to just 100 points in AS3. I think with typed arrays in Flash10, the snippet could run a lot more faster and would handle a lot more points. ;)

pwd

sekasi
August 26th, 2008, 04:07 AM
I hear that. If anything I'd like to see you tackle metaballs. It's an area where I've failed myself and would love to see some insight.

pwdVergesser
August 26th, 2008, 06:04 AM
I hear that. If anything I'd like to see you tackle metaballs. It's an area where I've failed myself and would love to see some insight.

can you explain what kind of "metaballic" things you want, īcause Iīve already played a lot with creating those stuff ( kind of slime- and bubble balls, foam a.s.o) ;) pwd

sekasi
August 26th, 2008, 06:45 AM
http://en.wikipedia.org/wiki/Metaballs

As long as it has user interaction, I don't really care. I know you're not crazy about posting code and I'm 100% fine with that. Just looking for a bit of insight ;)

pwdVergesser
August 26th, 2008, 09:25 AM
As long as it has user interaction, I don't really care. I know you're not crazy about posting code and I'm 100% fine with that. Just looking for a bit of insight ;)

the theory behind metaballs math is very easy, just some short lines of code (unoptimized as well):




package {

import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.events.*;
import flash.geom.Point;

public class Main extends Sprite {

// Declare variables
private var output:BitmapData;
private var buffer:BitmapData;
private var aPoint:Point;

private var threshold:Number;

private var b1_x:int;
private var b1_y:int;
private var b1_x_vel:int;
private var b1_y_vel:int;

private var b2_x:int;
private var b2_y:int;
private var b2_x_vel:int;
private var b2_y_vel:int;

private var b3_x:int;
private var b3_y:int;
private var b3_x_vel:int;
private var b3_y_vel:int;

public function Main() {

// Bitmapdata used for drawing to screen
buffer = new BitmapData(stage.stageWidth, stage.stageHeight, false);
output = new BitmapData(stage.stageWidth, stage.stageHeight, false);
aPoint = new Point(0, 0);

// Threshold that determines gooiness / size of metaballs
threshold = 1 / 25;

// Metaball 1 - coordinates and velocities
b1_x = 30;
b1_y = 30;
b1_x_vel = 2;
b1_y_vel = 1;

// Metaball 2 - coordinates and velocities
b2_x = 60;
b2_y = 90;
b2_x_vel = 4;
b2_y_vel = 6;

// Metaball 3 - coordinates and velocities
b3_x = 100;
b3_y = 100;
b3_x_vel = 5;
b3_y_vel = -3;

// Create new bitmap to draw output onto, then add to stage
addChild(new Bitmap(output));

// Set render as the main loop
stage.addEventListener(Event.ENTER_FRAME, render);

}

private function render( e:Event ):void {

// Apply velocity and check boundaries
b1_x += b1_x_vel; if ( b1_x > stage.stageWidth || b1_x < 0 ) { b1_x_vel *= -1; }
b1_y += b1_y_vel; if ( b1_y > stage.stageHeight || b1_y < 0 ) { b1_y_vel *= -1; }

b2_x += b2_x_vel; if ( b2_x > stage.stageWidth || b2_x < 0 ) { b2_x_vel *= -1; }
b2_y += b2_y_vel; if ( b2_y > stage.stageHeight || b2_y < 0 ) { b2_y_vel *= -1; }

b3_x += b3_x_vel; if ( b3_x > stage.stageWidth || b3_x < 0 ) { b3_x_vel *= -1; }
b3_y += b3_y_vel; if ( b3_y > stage.stageHeight || b3_y < 0 ) { b3_y_vel *= -1; }

// Iterate through each pixel in buffer and
// apply metaball formula : 1 / sqrt( (x1-x0)^2 + (y1-y0)^2 )
for ( var i:int = 0; i < buffer.width; i++ ) {
for ( var j:int = 0; j < buffer.height; j++ ) {

// The metaball formula - 1 / sqrt( (x1-x0)^2 + (y1-y0)^2 )
var ball_1:Number = 1 / Math.sqrt( ((i - b1_x) * (i - b1_x)) + ((j - b1_y) * (j - b1_y)) );
var ball_2:Number = 1 / Math.sqrt( ((i - b2_x) * (i - b2_x)) + ((j - b2_y) * (j - b2_y)) );
var ball_3:Number = 1 / Math.sqrt( ((i - b3_x) * (i - b3_x)) + ((j - b3_y) * (j - b3_y)) );

// Set pixel to black if falls within threshold
// Otherwise set white
if ( ball_1 + ball_2 + ball_3 > threshold ) {
buffer.setPixel(i, j, 0x000000);
}
else {
buffer.setPixel(i, j, 0xFFFFFF);
}

}
}

// Copy buffer into output
output.copyPixels(buffer, buffer.rect, aPoint);

}


}

}



pwd