B4J Question Sine wave a label (D.Y.C.P. scrolling)

ThRuST

Well-Known Member
Licensed User
Longtime User
How to make a label move in a smooth sine/cosine wave for example up and down or sideways in a transparent label. I would like to play around with this for a credits pane. A simple loop with values to play around with will help along way. Look forward to see some examples from you math gurus out there :)
As there's some different effects seen in past old-school demos from the C64 and the Amiga, what I am looking for is something more like a D.Y.C.P. Scroll effect, which means the char does not bend only wave in a sine. Sinewave scrollers is something else and that's not what I am looking for in this question. But if you have a sample source example please share it in here as well.
 

ThRuST

Well-Known Member
Licensed User
Longtime User
Oh and D.Y.C.P. stands for Different Y Character Position, as far as I can remember :)
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Faster version (still needs javaobject library and original toText sub)
B4X:
Sub AppStart (Form1 As Form, Args() As String)
 MainForm = Form1
 MainForm.Show
 Dim text As String = "Hello there how are you?"
 Dim offset As Double = 10.0d
 Dim cnt As Double = 0.0d
 Dim tx() As JavaObject = toText(text)
 For Each let As JavaObject In tx
  MainForm.RootPane.AddNode(let,offset,50,-1,-1)
 Next
 For w = 0 To 3600 ' just 10 iterations
  For Each letter As JavaObject In tx
   offset = offset + 10    ' gap between letters fixed spacing
   letter.RunMethod("setLayoutY",Array(100+(SinD(cnt+w)*60)))
   letter.RunMethod("setLayoutX",Array(offset))
   cnt = offset - 10.0d  ' to correct start position
  Next
  Sleep(0)
  offset = 10
  cnt = 0
 Next
End Sub

If you want to change font size / color etc
B4X:
Sub toText(s As String) As JavaObject()
 Dim res(s.Length) As JavaObject
 For c = 0 To s.Length -1
  Dim ts As String = s.CharAt(c)
  res(c).InitializeNewInstance("javafx.scene.text.Text",Array(ts))
  res(c).RunMethod("setFont",Array(fx.DefaultFont(20)))
  res(c).RunMethod("setFill",Array(fx.Colors.Red))
 Next
 Return res
End Sub
 
Last edited:
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
If you want proportional spacing for the text then modify code to
B4X:
...
 Do While True
  For w = 0 To 360
   For Each letter As JavaObject In tx
    letter.RunMethod("setLayoutY",Array(100+(SinD(cnt+w)*60)))
    letter.RunMethod("setLayoutX",Array(offset))
    offset = offset + getWidth(letter)
    cnt = offset - 10.0d
   Next
   Sleep(0)
   offset = 10
   cnt = 0
  Next
 Loop
...

And add this sub

B4X:
Sub getWidth(j As JavaObject) As Double    ' calculate the width of the letter
 Return j.RunMethodJO("getBoundsInLocal",Null).RunMethod("getWidth",Null)
End Sub
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
Wow awesome so many examples, great I will play around with these today. Have some cool ideas for how to display the credits, so a sine wave will open the gates to alot of fun effects :) @Daestrum What will the array look like for this line? Concerning ToText to make it work. All solutions looks interesting so I will try them all.
Is there a way to simulate that of a waving flag on an image or label? like in a wave-scroller, that would open up for some serious demo effects with B4J :cool: Cool

B4X:
Dim tx() As JavaObject = toText(text)
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
That line

B4X:
Dim tx() As JavaObject = toText(text)

Simply creates an array of JavaFX Text objects, one per character in the string.

It then manipulates the Y value to create the effect.

Will have a look at wibbly flags for you :)

Not sure if you noticed but the sine wave text example will work over other controls on a form. (just add the sine text after any other control on the pane).
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
@Daestrum Awesome, if I could just get this to work. Here's a screenshot, I must have missed to add something from your example

Capture.JPG
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
You need to add the sub at the bottom of post #4
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
@Daestrum Damn that looked cool. Reminds me of the old-school demos seen on C64 and Amiga. I noticed that it depend on the number in the for w next loop. I would like to have it in a timer since other stuff should be going on at the same time, so it can easily be combined with a wave image. Or a wave scroll on it's own with a pause function is always cool. If this can be done in B4J. I'll believe it when my eyes see it :) Turning into a demo-scene challenge here but that's just crazy and cool :cool:
B4J goes demo-style I'm lovin it :D
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
The version in post #5 changes it to run continuously in a do while loop.
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
Nice. How can I perform a basic calculation in a sub that does the calculation of a control (Label) everytime it is called. That could be really useful to move anything.
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
@Daestrum To get back to your example. It would be nice to shed some light on the calculation, so that any movement can be performed. Advanced math is beyond to be covered in the scope of this post, but some examples to play around with will be highly appreciated. For example, can the math fade out to be a straight line, like a bouncing effect that lands. And to reverse it, could be fun to play around with.

I found a nice example of a smooth never ending what I think is called a cosine movement. Look here to see what I mean. See how to logo smoothly stops and changes direction. A simple loop like that can make any image look fancy.
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
How to make a label move in a smooth sine/cosine wave for example up and down or sideways in a transparent label. I would like to play around with this for a credits pane. A simple loop with values to play around with will help along way. Look forward to see some examples from you math gurus out there :)
As there's some different effects seen in past old-school demos from the C64 and the Amiga, what I am looking for is something more like a D.Y.C.P. Scroll effect, which means the char does not bend only wave in a sine. Sinewave scrollers is something else and that's not what I am looking for in this question. But if you have a sample source example please share it in here as well.
Did you try the DisplacementMap demo of the SimpleGameEngine lib?
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
No, I must have missed that. Is it for B4J I assume? Do you have a link? I assume you made it then, since you're a GURU just like Erel and Daestrum :)
I'm playing around with the values in Daestrums example. It's great fun to play with these effects :)
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
Thanks I will check it out. Just turned Daestrums example into the coolest scroller I have ever seen with B4J :cool: Add this code and enjoy the show

B4X:
Do While True
        For w = 0 To 360
            For Each letter As JavaObject In tx
                letter.RunMethod("setLayoutY",Array(100+(SinD(cnt+w)*40)))
                letter.RunMethod("setLayoutX",Array(100+(SinD(cnt+w)*400)))
                'letter.RunMethod("setLayoutX",Array(offset))
                offset = offset - getWidth(letter)
                cnt = offset - 10.0d
            Next
            Sleep(0)
            offset = 10
            cnt = 0
        Next
    Loop

How to change the font size and colors? Can't wait to do that.
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
This looks even better. A horizontal sine circle scroll :cool: Makes B4J is the new demo platform

B4X:
Do While True
        For w = 0 To 360
            For Each letter As JavaObject In tx
                letter.RunMethod("setLayoutY",Array(200+(SinD(cnt+w*2)*40)))
                letter.RunMethod("setLayoutX",Array(100+(SinD(cnt+w)*400)))
                'letter.RunMethod("setLayoutX",Array(offset))
                offset = offset - getWidth(letter)
                cnt = offset - 5.0d
            Next
            Sleep(0)
            offset = 5
            cnt = 0
        Next
    Loop
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
@Informatix WOW that library sure looks awesome. Amazing, super-cool work damn that was impressive. Will take some time to look into though.
May I ask how long time you worked on it before you released it? Seems to have taken at least a years work. Hat off for that achievement. Will take a closer look at it for sure. Thanks :)
 
Upvote 0
Top