B4J Code Snippet [B4X] [XUI] Light Effect

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

B4X:
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/2) Mod 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
ezgif-com-crop-gif.67427
 

Attachments

  • B4J LightEffect.zip
    45.4 KB · Views: 553
  • B4A LightEffect.zip
    52.3 KB · Views: 543
Last edited:

Star-Dust

Expert
Licensed User
Longtime 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
 

Star-Dust

Expert
Licensed User
Longtime User
If you change the text to "Mario" I'm pretty sure it will work as it is on all platforms :p
it is possible, the source code knows where to find it
 
Top