B4J Code Snippet [B4X] [XUI] Light Effect

Discussion in 'B4J Code Snippets' started by Star-Dust, May 1, 2018.

  1. Star-Dust

    Star-Dust Expert Licensed User

    Have you ever thought of making a lighting effect on an image?
    If you do not, I thought about it ... this is a small code with a simple trick that allows you to get it with B4X

    Code:
    Sub ImageView1_Click
        Light(
    Sender)
    End Sub

    Sub ImageView2_Click
        Light(
    Sender)
    End Sub

    Sub Light(ImageView As B4XView)
        
    Dim xui As XUI
        
    Dim PanelBase As B4XView = xui.CreatePanel("")
        
    Dim PanelEffect As B4XView = xui.CreatePanel("")
        
    Dim Dv as int = 3  ' effect width = mBase.Width/Dv

        
    ImageView.Parent.AddView(PanelBase,ImageView.Left,ImageView.Top,ImageView.Width,ImageView.Height)
        PanelBase.BringToFront
        PanelBase.AddView(PanelEffect,-
    200DIP,-150dip,PanelBase.Width/Dv,PanelBase.Height+300dip)

        
    Dim Can As B4XCanvas
        
    Dim MaxW As Int = PanelEffect.Width-1

        Can.Initialize(PanelEffect)

        
    For x=0 To MaxW
            
    Dim C As Int = 255*(1-Sin(cPI*(((x+MaxW/2Mod MaxW)/MaxW)))
            Can.DrawLine(x,
    0,x,PanelEffect.Height,xui.Color_ARGB(C,255,255,255),1dip)
        
    Next
        PanelEffect.Rotation=
    45

        PanelEffect.SetLayoutAnimated(
    400,PanelBase.Width*1.8,0,PanelEffect.Width,PanelEffect.Height)

        Can.Invalidate
        Sleep(
    400)
        Can.Release
        PanelBase.RemoveViewFromParent
    End Sub
    ezgif.com-video-to-gif.gif [​IMG]
     

    Attached Files:

    Last edited: May 1, 2018
  2. Johan Hormaza

    Johan Hormaza Active Member Licensed User

  3. Erel

    Erel Administrator Staff Member Licensed User

    Great job!
     
  4. Star-Dust

    Star-Dust Expert Licensed User

    CHALLENGE:

    Who can reproduce this in B4X XUI.

    As usual LucaMS is not satisfied and has something to say, so he asked me for a change to the effect created, the reflection of light must hit only the writing and not the background and without losing speed.

    The view is a simple Label is not an Image, so you can change it as you wish.

    I made it in B4A, who can do it in B4X?

    video.gif
     
    LucaMs and Johan Hormaza like this.
  5. LucaMs

    LucaMs Expert Licensed User

    If you change the text to "Mario" I'm pretty sure it will work as it is on all platforms :p
     
  6. Star-Dust

    Star-Dust Expert Licensed User

    it is possible, the source code knows where to find it
     
    LucaMs likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice