• Print

Author Topic: Animation using Wood Letters  (Read 114 times)

Code Hunter

  • Newbie
  • *
  • Posts: 18
Animation using Wood Letters
« on: April 12, 2018, 10:45:30 pm »
I thought I would share this code for the animation it provides.

I hope someone finds it useful.

The code is provided here, but you also need to download the archive below which contains all the letters.

Code: [Select]
_TITLE "Wood Letters"

' Wood Letters courtesy of https://openclipart.org

SCREEN _NEWIMAGE(800, 320, 32)

DIM SHARED WoodColor AS _UNSIGNED LONG
WoodColor = _RGB(139, 90, 43)

LINE (0, 0)-(800, 320), WoodColor, BF

TYPE Alphabet
  image AS LONG
  imgWidth AS INTEGER
  imgHeight AS INTEGER
END TYPE

DIM SHARED Letters(26) AS Alphabet

DIM Text AS STRING

DIM File AS STRING
DIM Path AS STRING
Path = ".\Wood Letters\"

FOR i = 1 TO 26
  File = Path + "WoodTexture" + CHR$(64 + i) + "-300px.png"

  Letters(i).image = _LOADIMAGE(File)
  Letters(i).imgWidth = _WIDTH(Letters(i).image) \ 2
  Letters(i).imgHeight = _HEIGHT(Letters(i).image) \ 2
NEXT

' Animate in 'Code'
WoodText 1, 1, "Code", 1

' Animate in 'Hunter'
WoodText 1, 154, "Hunter", 1

' Halt the program
WHILE NOT Quit: WEND

SUB WoodText (x AS INTEGER, y AS INTEGER, Text AS STRING, Flag AS INTEGER)
' Make the Text all capital letters
Text = UCASE$(Text)

' Flag is used to enable(1)/disable(0) text animation
IF Flag THEN
  FOR i = LEN(Text) + 1 TO 1 STEP -1
    ' Clear the area drawn to
    LINE (x, y)-(x + 800, y + 150), WoodColor, BF

    ' Reset the start position
    xPos = x

    FOR t = 1 TO LEN(Text)
      ' Get the letter value
      ' (Each letter is 65-90 so subtract 64 to get the letter value)
      Char = ASC(MID$(Text, t, 1)) - 64

      ' Only allow valid value (1-26 A-Z)
      IF Char > 0 AND Char < 27 THEN
        ' Get Letter Width and Height
        W = Letters(Char).imgWidth
        h = Letters(Char).imgHeight

        ' Draw the Letter
        _PUTIMAGE (xPos, y)-(xPos + W, y + h), Letters(Char).image

        ' This has each letter moving outwards to the right
        IF t >= i THEN xPos = xPos + W + 2
      END IF
    NEXT

    _DISPLAY
    _DELAY .5
  NEXT
ELSE
  FOR t = 1 TO LEN(Text)
    Char = ASC(MID$(Text, t, 1)) - 64

    IF Char > 0 AND Char < 27 THEN
      W = Letters(Char).imgWidth
      h = Letters(Char).imgHeight

      _PUTIMAGE (xPos, y)-(xPos + W, y + h), Letters(Char).image

      IF t >= i THEN xPos = xPos + W + 2
    END IF
  NEXT
END IF
END SUB

  • Print