Author Topic: Time for Reflections  (Read 398 times)

Re: Time for Reflections
« Reply #15 on: June 25, 2018, 07:02:46 PM »
  • Best Answer
  • Petr,

    I'm going out on a limb here and guess, mainly by the 4meg file, that you have setup your program to scroll through the entire King James Version of the Bible? Although I like your choice in Version, may I suggest something a 'little' shorter, say Psalm 23 or Psalm 119? I'm not sure that most users will want read through the entire Bible in one sitting... lol

    By the way. Excellent job with the reflection.... Very cool.

    J

    Yes I did.  When I am using a text file to use for scrolling, or some other things, I mostly get out the KJV Bible because it is plenty of text.  Anyone can easily replace the file with their own text file.

    Thank you.  It wasn't difficult and had a running program in a very short time.

    Re: Time for Reflections
    « Reply #16 on: July 22, 2018, 10:15:47 PM »
  • Best Answer
  • I thought I would once more reflect on the reflection code.

    This is not the same code as before and it has some improvements added in to make it better.

    1) ESC will exit the program
    2) Text display is now able to change not only the font that is used but also the size as you can see when you run the program

    Before I  had it load font, display text, load next font and display, and back and forth.  This new code loads the font(s) in the beginning and then displays the text in the size desired which is much better and faster.

    Also in this one I removed loading text from a document and displaying it and just have a title text scrolled.

    I hope this code is usable for others, or just enjoyed by all.

    Code: [Select]
    _TITLE "Time for Reflection"

    DIM SHARED Pi AS SINGLE
    Pi = 3.141593

    ' \/\/\/\/\/
    ' Fireworks
    ' /\/\/\/\/\
    TYPE Pixel
      x AS DOUBLE
      y AS DOUBLE
    END TYPE

    DIM SHARED Stars(250) AS Pixel
    DIM SHARED Pixels(250) AS Pixel

    TYPE fireworks
      X AS SINGLE
      Y AS SINGLE
      T AS SINGLE
      G AS SINGLE
      P AS SINGLE
      S AS INTEGER

      Red AS INTEGER
      Green AS INTEGER
      Blue AS INTEGER

      Size AS INTEGER
    END TYPE

    DIM SHARED Sparkler AS fireworks

    Sparkler.G = 0.4
    Sparkler.P = 30

    Sparkler.Size = 1

    Sparkler.Red = 128 * RND + 128
    Sparkler.Green = 128 * RND + 128
    Sparkler.Blue = 128 * RND + 128
    ' \/\/\/\/\/
    ' Fireworks
    ' /\/\/\/\/\

    ' \/\/\/\/\/\/\/\/\/
    ' Frames per Second
    ' /\/\/\/\/\/\/\/\/\
    DIM SHARED fps AS INTEGER
    DIM SHARED frames AS INTEGER
    DIM SHARED oldTime AS STRING
    frames = 1
    oldTime = TIME$

    ' \/\/\/\/\/\/\/\/
    ' Screen Dimesions
    ' /\/\/\/\/\/\/\/\
    DIM SHARED sWidth AS INTEGER
    DIM SHARED sHeight AS INTEGER
    sWidth = 800
    sHeight = 600

    ' \/\/\/\/\/\/\/\/
    ' Center Dimesions
    ' /\/\/\/\/\/\/\/\
    DIM SHARED cWidth AS INTEGER
    DIM SHARED cHeight AS INTEGER
    cWidth = sWidth \ 2
    cHeight = sHeight \ 2

    ' \/\/\/\/\/\/\/\/\/\/\/\/
    ' Reflective floor height
    ' /\/\/\/\/\/\/\/\/\/\/\/\
    DIM SHARED rY AS INTEGER
    rY = sHeight - cHeight \ 2

    ' \/\/\/
    ' Fonts
    ' /\/\/\
    DIM SHARED Font(1024) AS LONG
    LoadFont 1, 13
    LoadFont 2, 20
    LoadFont 3, 37

    ' \/\/\/\/\/\/\/
    ' Text Dimesions
    ' /\/\/\/\/\/\/\
    DIM SHARED tWidth AS INTEGER
    DIM SHARED tHeight AS INTEGER
    tWidth = sWidth \ 16
    tHeight = sHeight \ 64

    ' \/\/\/\/\/\/\/
    ' Create Screen
    ' /\/\/\/\/\/\/\
    SCREEN _NEWIMAGE(sWidth, sHeight, 32)
    _FULLSCREEN

    ' \/\/\/\/\/\/\/\/\/\/
    ' Initialize Fireworks
    ' /\/\/\/\/\/\/\/\/\/\
    Sparkler.S = 1: Fireworks

    Main

    SUB Display (tx AS INTEGER, ty AS INTEGER, Text AS STRING, fValue AS INTEGER, tSize AS INTEGER)
    w = 8 * tSize
    h = 32 * tSize

    fv = 256 * (fValue - 1)

    tLen = LEN(Text)
    IF tLen > tWidth THEN tLen = tWidth

    FOR char = 1 TO tLen
      tChar = ASC(MID$(Text, char, 1)) + 1

      x = tx + w * (char - 1)
      _PUTIMAGE (x, ty)-(x + w, ty + h), Font(fv + tChar), 0
    NEXT
    END SUB

    SUB Main
    DIM Text AS STRING
    DIM Touch AS STRING

    textSize = 4
    tWidth = sWidth \ (8 * textSize)

    Text = "Reflections by Code Hunter"
    Text = SPACE$(tWidth) + Text + SPACE$(tWidth)

    tPos = 1
    frames = 1
    oldTime = TIME$

    WHILE NOT Quit
      LINE (0, 0)-(sWidth, sHeight), _RGBA32(0, 0, 0, 20), BF

      ' \/\/\/\/\/\/\/
      ' Draw Fireworks
      ' /\/\/\/\/\/\/\
      IF Sparkler.T < 75 THEN
        Sparkler.S = 0: Fireworks
      ELSE
        Sparkler.S = 1: Fireworks
      END IF

      ' \/\/\/\/\/\/\/\/\/\/\/
      ' Draw reflective Floor
      ' /\/\/\/\/\/\/\/\/\/\/\
      LINE (0, rY)-(sWidth, sHeight), _RGB(143, 143, 143), BF

      ' \/\/\/\/\/
      ' Show Text
      ' /\/\/\/\/\
      Display 0, rY + 8, MID$(Text, tPos, tWidth), 3, textSize

      ' \/\/\/\/\/\/\/\/\/
      ' Show Current Time
      ' /\/\/\/\/\/\/\/\/\
      Display 8, sHeight - 48, TIME$, 2, 2

      Touch = UCASE$(INKEY$)
      IF Touch = CHR$(27) THEN SYSTEM

      IF TIME$ <> oldTime THEN
        fps = frames
        frames = 1
        oldTime = TIME$
      ELSE
        frames = frames + 1
      END IF

      IF frames MOD 6 = 0 THEN
        tPos = tPos + 1
        IF tPos > LEN(Text) - tWidth THEN tPos = 1
      END IF

      LOCATE 2, 2: PRINT fps;

      _DISPLAY
      _LIMIT 60
    WEND
    END SUB

    SUB LoadFont (fontValue AS INTEGER, fontName AS INTEGER)
    DIM Char AS STRING

    DIM Temp AS STRING
    Temp = RIGHT$("0" + LTRIM$(STR$(fontName)), 2) + ".DAT"

    OPEN ".\BinFonts\BINFNT" + Temp FOR INPUT AS #1

    Value = (fontValue - 1) * 256
    FOR fchar = 1 TO 256
      INPUT #1, Char

      Font(Value + fchar) = _NEWIMAGE(8, 32, 32)
      _DEST Font(Value + fchar)

      FOR v = 0 TO 15
        Temp = MID$(Char, 8 * v + 1, 8)

        FOR h = 0 TO 7
          IF MID$(Temp, h + 1, 1) = "1" THEN
            PSET (h, v), _RGB(0, 0, 0)
          END IF
        NEXT

        c = 160 - 8 * v

        FOR h = 0 TO 7
          IF MID$(Temp, h + 1, 1) = "1" THEN
            PSET (h, 24 - v), _RGB(c, c, c)
          END IF
        NEXT
      NEXT
    NEXT

    CLOSE #1

    _DEST 0
    END SUB

    SUB Fireworks
    EXIT SUB

    IF Sparkler.S = 1 THEN
      Sparkler.T = 0
      Sparkler.X = sWidth * RND
      Sparkler.Y = sHeight * RND

      Sparkler.Red = 128 * RND + 128
      Sparkler.Green = 128 * RND + 128
      Sparkler.Blue = 128 * RND + 128

      Choice = 3 * RND

      FOR i = 0 TO UBOUND(Pixels)
        Pixels(i).x = RND * COS(2 * Pi * RND)
        Pixels(i).y = RND * SIN(2 * Pi * RND)
      NEXT
    END IF

    r = Sparkler.Red
    g = Sparkler.Green
    b = Sparkler.Blue

    s = Sparkler.Size

    COLOR _RGB(r, g, b)

    FOR i = 0 TO UBOUND(Pixels)
      Stars(i).x = Sparkler.X + Sparkler.T * Sparkler.P * Pixels(i).x
      Stars(i).y = Sparkler.Y + Sparkler.T * Sparkler.P * Pixels(i).y + Sparkler.T * Sparkler.G * Sparkler.T

      PSET (Stars(i).x, Stars(i).y), _RGB(r, g, b)
    NEXT

    Sparkler.T = Sparkler.T + 0.1
    END SUB

    Re: Time for Reflections
    « Reply #17 on: July 23, 2018, 12:44:38 AM »
  • Best Answer
  • Little update to above code.

    Remove Line 227 that reads: "Exit Sub" and you will get the fireworks working.

    Re: Time for Reflections
    « Reply #18 on: July 23, 2018, 09:44:18 AM »
  • Best Answer
  • Yeah, I needed to remove that line but also I had to remove  the .\ from this line in LoadFont sub:
    OPEN ".\BinFonts\BINFNT" + Temp FOR INPUT AS #1

    I wonder if this is a Windows 10 thing? The beginning .\ never gets the file loaded.

    Plus, I had to save the source in the folder given in Original Post zip file.

    All this, and I can't quite remember what is different between the 2 versions?

    The reflected text is nice of course, maybe you wanted us to admire your work again. ;-))

    B = B + ...
    QB64 x 64 v1.2 2018 0228/86 git b30af92
    QB64 v1.2 2018 0228/86 git b30af92
    QB64 v1.1 2017 1106/82

    Re: Time for Reflections
    « Reply #19 on: July 23, 2018, 07:18:33 PM »
  • Best Answer
  • Yeah, I needed to remove that line but also I had to remove  the .\ from this line in LoadFont sub:
    OPEN ".\BinFonts\BINFNT" + Temp FOR INPUT AS #1

    I wonder if this is a Windows 10 thing? The beginning .\ never gets the file loaded.

    Plus, I had to save the source in the folder given in Original Post zip file.

    All this, and I can't quite remember what is different between the 2 versions?

    The reflected text is nice of course, maybe you wanted us to admire your work again. ;-))

    I was having problems copying the code into the post so I ended up crating a text file of the post and then copying the text in its entirety into the post to get it to work.  Everytime I tried to copy the code it would freeze the cursor on the post and I had to wait for it to unfreeze.  In all my frustration I forgot to remove the lines and I forgot to mention about the binary fonts from the original code.

    The ".\" is from DOS and it means "Start in this directory" Say you have a directory called Reflections and in the Reflections directory you have the BINFonts folder and were going to access the BinFonts folder you could use ".\BINFonts" which is to say in this current folder look for BINFonts and access the file in that folder.

    I hope that makes sense.

    In Linux (which is what I use for my main OS) it has a similiar command but uses "./".  But, as someone pointed out (I believe it was Fellippe) in QB64 you can use either "./" or ".\" and it doesn't matter.  What matters is you have the BINFonts folder and its contents in the same folder with the main code for it to work.

    Look at the original code and the new code and you will see how they differ.  Yes they both use the fireworks and the reflections, but this new code has 3 fonts loaded and can use any of them, but the original code it would load a font, display, load another font display and back and forth constantly using up disk access.  The new code doesn't.  Also the new code has the ability to enlarge the text as well as use specific fonts.  I haven't added in colour yet, but that is planned at some point.

    Well, there you have it.  My longest winded reply yet (code doesn't count),  I just thought I would show an improved version that is better coded and will run MUCH faster on any system.

    Last note: The reason the new code is much faster (if you look at the code) is that the original used a loop each time to draw the font characters and the reflections.  In the new code, it actually loads the font and creates the font along with the reflections at the start of the program and then uses _PutImage to draw the font with reflection.  One advantage (besides speed) is you can easily resize the font as you want and it is faster than trying to do it manually.