Computer Science Canada

Oval Glow Effect

Author:  ynotpeace [ Wed Dec 08, 2010 10:46 pm ]
Post subject:  Oval Glow Effect

Since Turing default colors is only 8-bit, I tried to play around with the RGB to get something cooler.
So I came up with a Glowing Oval effect
Turing:


setscreen("graphics,nobuttonbar,title:Glow Effect")
colorback (black)
cls
proc Glowoval (normal, back, glow : string, Bradius, glowradius, inradius, intenseradius, xt, yt : int, glowcheck : boolean)
    var RGBinter : array 1 .. 3 of real
    var RGBinterglow : array 1 .. 3 of real
    const inter : int := Bradius
    const glowinter : int := glowradius
    const width : int := inradius
    const intens : int := intenseradius %NOTE:intensity must be smaller then width
    var glowcolor : array 1 .. 3 of real
    var startcolor : array 1 .. 3 of real
    var backcolor : array 1 .. 3 of real
    var x, y : int
    x := xt
    y := yt
    startcolor (1) := strint (normal (6) + normal (7), 16) / 256
    startcolor (2) := strint (normal (4) + normal (5), 16) / 256
    startcolor (3) := strint (normal (2) + normal (3), 16) / 256
    backcolor (1) := strint (back (6) + back (7), 16) / 256
    backcolor (2) := strint (back (4) + back (5), 16) / 256
    backcolor (3) := strint (back (2) + back (3), 16) / 256
    if glowcheck = true then
        glowcolor (1) := strint (glow (6) + glow (7), 16) / 256
        glowcolor (2) := strint (glow (4) + glow (5), 16) / 256
        glowcolor (3) := strint (glow (2) + glow (3), 16) / 256
    else
        glowcolor (1) := startcolor (1) + ((1 - startcolor (1)) * 0.7)
        glowcolor (2) := startcolor (2) + ((1 - startcolor (2)) * 0.7)
        glowcolor (3) := startcolor (3) + ((1 - startcolor (3)) * 0.7)
    end if
    RGBinter (1) := (backcolor (1) - startcolor (1)) / inter
    RGBinter (2) := (backcolor (2) - startcolor (2)) / inter
    RGBinter (3) := (backcolor (3) - startcolor (3)) / inter
    RGBinterglow (1) := (glowcolor (1) - startcolor (1)) / glowinter
    RGBinterglow (2) := (glowcolor (2) - startcolor (2)) / glowinter
    RGBinterglow (3) := (glowcolor (3) - startcolor (3)) / glowinter
    for decreasing i : inter - 1 + glowinter + width .. glowinter + width
        RGB.SetColor (1, startcolor (1) + ((i - glowinter - width) * RGBinter (1)),
            startcolor (2) + ((i - glowinter - width) * RGBinter (2)),
            startcolor (3) + ((i - glowinter - width) * RGBinter (3)))
        Draw.FillOval (x, y, i, i, 1)
    end for
    for decreasing i : glowinter + width - 1 .. width
        RGB.SetColor (1, startcolor (1) + (((glowinter + width) - i) * RGBinterglow (1)),
            startcolor (2) + ((glowinter + width) - i) * RGBinterglow (2),
            startcolor (3) + ((glowinter + width) - i) * RGBinterglow (3))
        Draw.FillOval (x, y, i, i, 1)
    end for
    for decreasing i : width - 1 .. width - intens
        RGB.SetColor (1, glowcolor (1) + ((width - i) * (1 - glowcolor (1)) / intens),
            glowcolor (2) + ((width - i) * (1 - glowcolor (2)) / intens),
            glowcolor (3) + ((width - i) * (1 - glowcolor (3)) / intens))
        Draw.FillOval (x, y, i, i, 1)
    end for
    View.Update
    color(31)
    put startcolor(1)*256
    put startcolor(2)*256
    put startcolor(3)*256
end Glowoval


Glowoval ("#41C333", "#000000", "#FFFFFF", 8, 10, 40, 20, 200, 200, true)


/*EXAMPLE 2(uncomment to see)
Glowoval ("#41C333", "#000000", "#FFFFFF", 10, 10, 60, 2, 200, 200, true)
Glowoval ("#41C333", "#FFFFFF", "#000000", 20, 25, 10, 0, 200, 200, true)
*/


Parameters are:
Glowoval(object color,background color, glow color, fade out radius,glowing radius,center glow radius,intensity,x,y,manual glow check)
most of it is pretty self explanatory.
For Manual glow check, if set to false, the procedure automatically finds the glowing color with is just a whiter shade of the object color.
Please comment and help me improve on this.
(as you can see in example 2, you can play around with the settings and make some neat stuff.)
I also find that sometimes some hex colors don't work for some reason :S
Thanks!

Author:  SNIPERDUDE [ Thu Dec 09, 2010 7:23 pm ]
Post subject:  RE:Oval Glow Effect

That is actually really cool, one of the better graphical effect engines I've seen in Turing in a while.
+bits

Author:  ynotpeace [ Thu Dec 09, 2010 9:18 pm ]
Post subject:  Re: Oval Glow Effect

Ok fixed the color problem and added some stuff to make this complete.

Parameters:

Glowoval(object color,background color,glow color, fade radius, transition glow radius, in glow radius, intensity, object radius, x, y, x-radius factor, y-radius factor, manual glow check)

Explanation:

Object color: The color of the oval.
Background color: Color of background.
Glow color: The color you want your object to glow into.
Fade radius: The outer rim of oval, fades from object color to background color.
Transition glow radius: The length of pixels it takes for the object color to transition to the glow color.
In glow radius: Length in pixels of the radius of the inner "white".
Intensity: Transition between the glow color to white (the less this value is the more intense it will look).
Object radius: This is between the fade radius and transition glow radius. It is the length in pixels of pure object color.
x: x positioning.
y: y positioning.
x-radius factor, y-radius factor: Determines the stretch or compression factor of the oval (example:(1,2) would make the oval very tall).
Manual glow check: If left false, engine will automatically generate a glow color (whiter shade of the object color). (please note that even left false please enter a blank string for the glow color ).


Turing:

setscreen ("graphics:600;600,nobuttonbar,title:Glow Effect")
colorback (black)
cls
proc Glowoval (normal, back, glow : string, Bradius, glowradius, inradius, intenseradius, objectradius, xt, yt : int, xr, yr : real, glowcheck : boolean)
    var RGBinter : array 1 .. 3 of real
    var RGBinterglow : array 1 .. 3 of real
    const inter : int := Bradius
    const glowinter : int := glowradius
    const width : int := inradius
    const intens : int := intenseradius %NOTE:intensity must be smaller then width
    const object : int := objectradius
    var glowcolor : array 1 .. 3 of real
    var startcolor : array 1 .. 3 of real
    var backcolor : array 1 .. 3 of real
    var x, y : int
    x := xt
    y := yt
    startcolor (1) := strint (normal (2) + normal (3), 16) / 256
    startcolor (2) := strint (normal (4) + normal (5), 16) / 256
    startcolor (3) := strint (normal (6) + normal (7), 16) / 256
    backcolor (1) := strint (back (2) + back (3), 16) / 256
    backcolor (2) := strint (back (4) + back (5), 16) / 256
    backcolor (3) := strint (back (6) + back (7), 16) / 256
    if glowcheck = true then
        glowcolor (1) := strint (glow (2) + glow (3), 16) / 256
        glowcolor (2) := strint (glow (4) + glow (5), 16) / 256
        glowcolor (3) := strint (glow (6) + glow (7), 16) / 256
    else
        glowcolor (1) := startcolor (1) + ((1 - startcolor (1)) * 0.7)
        glowcolor (2) := startcolor (2) + ((1 - startcolor (2)) * 0.7)
        glowcolor (3) := startcolor (3) + ((1 - startcolor (3)) * 0.7)
    end if
    RGBinter (1) := (backcolor (1) - startcolor (1)) / inter
    RGBinter (2) := (backcolor (2) - startcolor (2)) / inter
    RGBinter (3) := (backcolor (3) - startcolor (3)) / inter
    RGBinterglow (1) := (glowcolor (1) - startcolor (1)) / glowinter
    RGBinterglow (2) := (glowcolor (2) - startcolor (2)) / glowinter
    RGBinterglow (3) := (glowcolor (3) - startcolor (3)) / glowinter
    for decreasing i : inter - 1 + glowinter + width + object .. glowinter + width + object
        RGB.SetColor (1, startcolor (1) + ((i - glowinter - width - object) * RGBinter (1)),
            startcolor (2) + ((i - glowinter - width - object) * RGBinter (2)),
            startcolor (3) + ((i - glowinter - width - object) * RGBinter (3)))
        Draw.FillOval (x, y, i + round (i * xr), i + round (i * yr), 1)
    end for

    for decreasing i : glowinter + width - 1 .. width
        RGB.SetColor (1, startcolor (1) + (((glowinter + width) - i) * RGBinterglow (1)),
            startcolor (2) + ((glowinter + width) - i) * RGBinterglow (2),
            startcolor (3) + ((glowinter + width) - i) * RGBinterglow (3))
        Draw.FillOval (x, y, i + round (i * xr), i + round (i * yr), 1)
    end for
    for decreasing i : width - 1 .. width - intens
        RGB.SetColor (1, glowcolor (1) + ((width - i) * (1 - glowcolor (1)) / intens),
            glowcolor (2) + ((width - i) * (1 - glowcolor (2)) / intens),
            glowcolor (3) + ((width - i) * (1 - glowcolor (3)) / intens))
        Draw.FillOval (x, y, i + round (i * xr), i + round (i * yr), 1)
    end for
    View.Update



end Glowoval
var mx, my, button : int
var r, g, b : int
var count : int := 0
var cc : int := 1
var colr : string
r := 255
g := 0
b := 0
loop
    count := count + 1
    if count = 85 then
        count := 1
        cc := cc + 1
    end if
    if cc = 7 then
        cc := 1
    end if
    if cc = 1 then
        g := g + 3
    elsif cc = 2 then
        r := r - 3
    elsif cc = 3 then
        b := b + 3
    elsif cc = 4 then
        g := g - 3
    elsif cc = 5 then
        r := r + 3
    elsif cc = 6 then
        b := b - 3
    end if
    if r < 16 then
        colr := "#" + "0" + intstr (r, 1, 16)
    else
        colr := "#" + intstr (r, 2, 16)
    end if
    if g < 16 then
        colr := colr + "0" + intstr (g, 1, 16)
    else
        colr := colr + intstr (g, 2, 16)
    end if
    if b < 16 then
        colr := colr + "0" + intstr (b, 1, 16)
    else
        colr := colr + intstr (b, 2, 16)
    end if

    button := Rand.Int (40, 50)
    Glowoval (colr, "#000000", "#D1FFFF", ceil (button / 5), ceil (button * 0.2), ceil (button * 0.8), ceil (56 - (button)), 50 - ceil (button * 0.4) - ceil (button * 0.6), round (maxx /
        2),
        round (maxy / 2), 1, 1, false)
    delay (90)
    cls
end loop
%Glowoval ("#3DFFFF", "#000000", "#FFFFFF", 10, 10, 60, 2,0, round(maxx/2), round(maxy/2),1,1, true)
%Glowoval ("#3DFFFF", "#FFFFFF", "#000000", 20, 25, 10, 0,0, round(maxx/2), round(maxy/2),1,1, true)


if you wanna check out the simple examples then comment out the main program and check the 2 examples towards the bottom of the program.


: