'RAINBOW.BAS calculates a LVL file with colors ranging from 
'  red-yellow-green-cyan-blue.
' Contour lines are invisible by default.  For Solid contour lines, change 
'  Invisible to Solid in s1$.
' Original SURF_LVL.BAS by Jud Ahern, University of Oklahoma, written in 
'  QBASIC.
' Port to SURFER Scripter BASIC by Tom Bresnahan, Golden Software, Inc. 11/94.


DIM contour(100)

header$ = "'Level Flags LColor LStyle LWidth FFGColor FBGColor FPattern FMode"
q$ = CHR$(34)  ' a double quote
sp$ = CHR$(32) ' a space
s1$ = "0 " + q$ + "Black" + q$ + sp$ + q$ + "Invisible" + q$ + " 0 " + q$
s3$ = q$ + sp$ + q$ + "White" + q$ + sp$ + q$ + "Solid" + q$ + " 2"
form$ = s1$ + s2$ + s3$

lvlfile$=INPUTbox$( "Name of level file to create - must be .lvl")
cmin=val(inputbox$( "Minimum contour value: "))
cmax=val(inputbox$( "Maximum contour value: "))
interval=val(inputbox$( "Contour interval: "))
OPEN lvlfile$ FOR OUTPUT AS #1

nlvls = (cmax - cmin) / interval - 1      ' was + 1, not -1
CLS()
FOR i = 1 TO nlvls
    contour(i) = cmin + i * interval      ' was (i - 1) *, not i *
    NEXT 
end2 = INT(nlvls / 2)
end1 = INT(end2 / 2)
end3 = end2 + INT((nlvls - end2) / 2)

PRINT #1, "LVL2"
PRINT #1, header$

FOR i = 1 TO end1
    r = 0
    b = 255
    g = INT((255 / (end1 - 1)) * (i - 1))
    r$ = RIGHT$(STR$(r), LEN(STR$(r)) - 1)
    g$ = RIGHT$(STR$(g), LEN(STR$(g)) - 1)
    b$ = RIGHT$(STR$(b), LEN(STR$(b)) - 1)
    PRINT contour(i);" ";r$;" "; g$;" "; b$
    PRINT #1, contour(i);" ";s1$+"R"+R$+" G"+G$+" B"+B$+s3$
NEXT 
FOR i = end1 + 1 TO end2
    r = 0
    g = 255
    b = 255 - INT(255 / (end2 - end1) * (i - end1))
    r$ = RIGHT$(STR$(r), LEN(STR$(r)) - 1)
    g$ = RIGHT$(STR$(g), LEN(STR$(g)) - 1)
    b$ = RIGHT$(STR$(b), LEN(STR$(b)) - 1)
    PRINT contour(i);" ";r$;" "; g$;" "; b$
    PRINT #1, contour(i);" ";s1$+"R"+R$+" G"+G$+" B"+B$+s3$
NEXT 
FOR i = end2 + 1 TO end3
    b = 0
    g = 255
    r = INT(255 / (end3 - end2) * (i - end2))
    r$ = RIGHT$(STR$(r), LEN(STR$(r)) - 1)
    g$ = RIGHT$(STR$(g), LEN(STR$(g)) - 1)
    b$ = RIGHT$(STR$(b), LEN(STR$(b)) - 1)
    PRINT contour(i);" ";r$;" "; g$;" "; b$
    PRINT #1, contour(i);" ";s1$+"R"+R$+" G"+G$+" B"+B$+s3$
NEXT 
FOR i = end3 + 1 TO nlvls
    r = 255
    b = 0
    g = 255 - INT(255 / (nlvls - end3) * (i - end3))
    r$ = RIGHT$(STR$(r), LEN(STR$(r)) - 1)
    g$ = RIGHT$(STR$(g), LEN(STR$(g)) - 1)
    b$ = RIGHT$(STR$(b), LEN(STR$(b)) - 1)
    PRINT contour(i);" ";r$;" "; g$;" "; b$
    PRINT #1, contour(i);" ";s1$+"R"+R$+" G"+G$+" B"+B$+s3$
NEXT 
END
close #1
'LVL2


' 52200 0 "Black" "Invisible" 0 "R0 G60 B255" "White" "Solid" 2

