Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
a little tutorial STEP by STEP on scrolling in 2D graphic mode
#10
(12-02-2024, 07:27 PM)Pete Wrote: Now let's see a SCREEN 0 example!!!

Actually that's the one thing I haven't yet coded in SCREEN 0, a lateral scroll routine. The IDE uses one, which I presume is written in SCREEN 0.

Hmm, with arrays it's pretty easy...

Use arrow left and right keys to laterally scroll the text on the screen.
Code: (Select All)
ReDim l$(20)
For h = 1 To 20
    For i = 1 To Rnd * 50 + 60
        j = Int(Rnd * 10 + 48)
        l$ = l$ + Chr$(j)
        If Int(Rnd * 7) = 1 And Right$(l$, 1) <> " " Then l$ = l$ + " "
    Next
    l$(h) = l$: l$ = ""
Next
k = 1
Do
    For i = 1 To 20
        Locate i, 1:
        a$ = Space$(_Width)
        Mid$(a$, 1) = Mid$(l$(i), k, _Width)
        Print a$;
    Next
    Do
        _Limit 60
        b$ = InKey$
        Select Case b$
            Case Chr$(27): End
            Case Chr$(0) + "K"
                If k > 0 Then k = k - 1: Exit Do
            Case Chr$(0) + "M"
                k = k + 1: Exit Do
        End Select
    Loop
Loop

Now if the text is a single variable with line breaks, that would require a slightly different approach.
Code: (Select All)
Width 80, 25
_ScreenMove _Middle
For h = 1 To 20
    For i = 1 To Rnd * 50 + 60
        j = Int(Rnd * 10 + 48)
        a$ = a$ + Chr$(j)
        If Int(Rnd * 7) = 1 And Right$(a$, 1) <> " " Then a$ = a$ + " "
    Next
    a$ = a$ + Chr$(13) + Chr$(10)
Next
Rem a$ = _Clipboard$
Do
    seed = 1
    For i = 1 To 20
        Locate i, 1
        a1$ = Mid$(a$, seed, _Width + k)
        If k < InStr(a1$ + Chr$(13), Chr$(13)) Then a1$ = Mid$(a1$, k + 1) Else a1$ = ""
        If InStr(a1$, Chr$(13)) Then a1$ = Mid$(a1$, 1, InStr(a1$, Chr$(13)) - 1)
        x$ = Space$(_Width)
        Mid$(x$, 1) = a1$
        Print x$;
        seed = InStr(seed, a$, Chr$(13)) + 2
    Next
    Do
        _Limit 60
        b$ = InKey$
        Select Case b$
            Case Chr$(27): End
            Case Chr$(0) + "K"
                If k > 0 Then k = k - 1: Exit Do
            Case Chr$(0) + "M"
                k = k + 1: Exit Do
        End Select
    Loop
Loop

Anyway, not goof proofed so if you remove the remark at the _clipboard option just be sure you copy enough text to cover 20 or more lines. This is just what I would start out with a s way of displaying and horizontally scrolling text in SCREEN 0.

Pete
Hi Pete
your scrolling in SCREEN 0 is very interesting. As I have seen it I remembered when I saw for the first time the Text-windows in Turbo Pascal 6.0 in which you can scroll to right and to bottom beyond the text in the window.
So you bring me to imagine a demo
here it is

Code: (Select All)


Width 80, 25 ' screen 0 only text 80 columns for 25 rows
_ControlChr Off
_Title "Scrolling text in SCREEN 0 with arrow keys"
Dim Row As String, Text(1 To 40) As String, cText(1 To 255, 1 To 40) As Integer, a As Integer, b As Integer, R As Integer, C As Integer
' initialization

' it builds a string of 255 characters
For a = 1 To 255
    Row = Row + Chr$(a)
Next a
' it builds  40 rows of 255 characters for row
For a = 1 To 40
    Text(a) = Right$(Row, a + 10) + Left$(Row, 255 - a - 10)
    For b = 1 To 255
        cText(b, a) = (b * a) Mod 7
    Next b
Next a

Row = ""
R = 1
C = 1
While Row <> "Q"
    Row = UCase$(InKey$)

    If Row = Chr$(0) + "H" Then R = R - 1
    If Row = Chr$(0) + "P" Then R = R + 1

    If Row = Chr$(0) + "K" Then C = C - 1
    If Row = Chr$(0) + "M" Then C = C + 1

    Cls , 0
    For a = 0 To 24
        Locate a + 1, 1
        If (a + R) < 41 And (a + R) > 0 Then
            For b = 1 To 80
                If (C + b - 1 < 256) And (C + b - 1 > 0) Then
                    Color , cText(C + b - 1, a + R)
                    Print Mid$(Text(a + R), C + b - 1, 1);
                Else
                    Color , 0
                    Print " ";
                End If

            Next b
        End If
    Next
    _Display
    _Limit 100
Wend
End
I hope you don't mind
Reply


Messages In This Thread
RE: a little tutorial STEP by STEP on scrolling in 2D graphic mode - by TempodiBasic - 12-04-2024, 01:51 AM



Users browsing this thread: 17 Guest(s)