Computer Science Canada

Lens Flare

Author:  Martin [ Tue Apr 22, 2003 11:37 pm ]
Post subject:  Lens Flare

I didn't alpha blend it so it looks kinda crappy

code:

%Lens flare effect
View.Set ("graphics:640;480,title:Lens Flare Demo,nobuttonbar")
colourback (black)
cls

var lx, ly : int
lx := 300
ly := 300

var cx, cy : int
cx := maxx div 2
cy := maxy div 2

var vx, vy : int
vx := cx - lx
vy := cy - ly

fcn distance (x1 : int, y1 : int, x2 : int, y2 : int) : real
    result sqrt ((x1 - x2) ** 2 + (y1 - y2) ** 2)
end distance

var d1 := distance (lx, ly, cx, cy)
var d2 := distance (vx, vy, cx, cy)
var burst : array 1 .. 3 of int
burst (1) := Pic.FileNew ("flare.bmp")
burst (2) := Pic.Scale (burst (1), 32, 32)
burst (3) := Pic.Scale (burst (1), 64, 64)
var halo : array 1 .. 3 of int
halo (1) := Pic.FileNew ("halo1.bmp")
halo (2) := Pic.FileNew ("halo2.bmp")
halo (3) := Pic.FileNew ("halo3.bmp")
for i : 1 .. 3
    Pic.SetTransparentColour (burst (i), black)
    Pic.SetTransparentColour (halo (i), black)
end for

var mx, my, b : int
View.Set ("offscreenonly")
loop
    Mouse.Where (mx, my, b)
    lx := mx - cx
    ly := my - cy
    Pic.Draw (halo (1), (lx div 2) + cx - 64, (ly div 2) + cy - 64, picMerge)
    Pic.Draw (halo (2), lx div 8 + cx - 64, ly div 8 + cy - 64, picMerge)
    Pic.Draw (halo (3), -lx div 4 + cx - 64, -ly div 4 + cy - 64, picMerge)
    Pic.Draw (burst (1), lx + cx - 64, ly + cy - 64, picMerge)
    Pic.Draw (burst (2), cx - lx div 3 - 16, cy - ly div 3 - 16, picMerge)
    Pic.Draw (burst (3), (-lx div 2) + cx - 32, (-ly div 2) + cy - 32, picMerge)

    View.Update
    cls
end loop

Author:  jamez [ Wed Apr 23, 2003 8:19 am ]
Post subject: 

thats pretty cool Very Happy


: