' Made for the Vintage Computing Christmas Challenge 2021
' By David Jalbert
' Twitter: https://twitter.com/DavidJayIndie

' Sets the seed for the random number generator with the current time
randomize timer

' Shared constants
dim shared LineWidth
LineWidth = 40
dim shared LineHalfWidth
LineHalfWidth = LineWidth / 2

' Draws a centered line of colored X'es
sub drawLine(numChars, isTrunk)
    ' Defines where the X'es start and end
    charStart = int(LineHalfWidth - numChars / 2)
    charEnd = int(LineHalfWidth + numChars / 2)
    
    ' Defines the random position where the light bulb should appear
    bulbPosition = int(charStart + rnd * (numChars - 1))
    
    ' Draws the line character by character
    for i = 0 to LineWidth
        ' Checks if the counter is inside the range of X'es
        if i >= charStart and i < charEnd then
            ' Checks if the line is the trunk
            if isTrunk = 1 then
                color(6), (0)
            else
                ' Checks if the counter is at the light bulb position
                if i = bulbPosition then
                    color(28), (4)
                else
                    color(2), (0)
                end if
            end if
            ' The colors have been set, now print the X
            print "*";
        else
            ' Otherwise, print an empty space
            color(7), (0)
            print " ";
        end if
    next
    
    ' Prints a new line
    print ""
end sub

' Draws each line with parameters for the width and type
drawLine(1), (0)
drawLine(3), (0)
drawLine(5), (0)
drawLine(7), (0)
drawLine(3), (0)
drawLine(7), (0)
drawLine(11), (0)
drawLine(5), (0)
drawLine(9), (0)
drawLine(13), (0)
drawLine(19), (0)
drawLine(3), (1)
drawLine(3), (1)