Computer Science Canada

[source code] motion blur

Author:  Tony [ Sun Nov 09, 2003 3:51 pm ]
Post subject:  [source code] motion blur

based on my blur filter and thx to thoughtful for the idea Very Happy

Motion Blur is used to blur images in a direction and with magnitude, creating an effect of the object moving in that direction.

code:

%a more advanced version of the Blur Filter.
%This includes the direction and magnitude of the blur
%so that motion blurs can be created

procedure Blur(direction:int, magnitude:int)
var d:array 1..maxx, 1..maxy of int %vertual image, holds pixel colors
var c:int:=255 %just a variable for color
var cr,cb,cg:array 1..magnitude of real %temporary colors
var acr,acb,acg:real %used for average color calculation

for x:1..maxx
for y:1..maxy
d(x,y):=whatdotcolor(x,y) %records pixel colors
end for
end for

for x:magnitude..maxx-magnitude
for y:magnitude..maxy-magnitude

for m:1..magnitude
RGB.GetColor(d(x+round(cosd(direction)*m),y+round(sind(direction)*m)),cr(m),cg(m),cb(m))
end for

acr:=0
for i:1..magnitude
acr+=cr(i)
end for
acr:=acr/magnitude %average color

acg:=0
for i:1..magnitude
acg+=cg(i)
end for
acg:=acg/magnitude %average color

acb:=0
for i:1..magnitude
acb+=cb(i)
end for
acb:=acb/magnitude %average color


RGB.SetColor(c,acr,acg,acb) %create the new color
Draw.Dot(x,y,c) %draw that color
end for
end for

end Blur


Not much has changed. The only difference really is that trig is used to find which points to blur together.

Direction:int is degrees at which to blur, Magnitude:int is how many pixels in that direction will be blured.

Here're some SS:
Blur(0,10)
Posted Image, might have been reduced in size. Click Image to view fullscreen.

Blur(0,10) + redraw of text
Posted Image, might have been reduced in size. Click Image to view fullscreen.

Blur(45,25) + redraw of text
Posted Image, might have been reduced in size. Click Image to view fullscreen.

Note, I've left a border around the image of "Magnitude:int" length, so that filter would not crash, trying to get the color of a pixel outside the screen

Author:  rizzix [ Sun Nov 09, 2003 7:39 pm ]
Post subject: 

as i said nice stuff

Author:  thoughtful [ Mon Nov 10, 2003 3:38 pm ]
Post subject: 

Hey tony this is jus great, i wasn't expecting an effect this great this fast. it is splendid. Smile Very Happy


: