Follow

How can I use a Surfer script to fill my contours with a custom rainbow fill?

This article contains a sample script for creating a rainbow fill level (LVL) file for filled contours.

To run this script:

  1. Copy the script below, or download the attached BAS file: rainbow.bas.
  2. In a Windows Explorer window, navigate to C:\Program Files\Golden Software\Surfer 14\Scripter.
  3. Double click on Scripter.exe to launch Scripter.
  4. Press Ctrl+A to select all of the existing lines then press Delete.
  5. If you copied this script, press Ctrl+V to paste it into Scripter. If you downloaded it, click File | Open, select the BAS file from your downloads directory, and click Open.
  6. Click Script | Run to run the script.
     

*********

'============================================================================
'	RAINBOW.BAS
'
'	This script creates a LVL file with colors ranging from 
'		red-yellow-green-cyan-blue.
'    
'	Contour lines are solid by default.  For invisible contour lines, change
'		Solid to Invisible in s1$.

'============================================================================

Sub Main

Dim contour(1000)

header$ = "'Level Flags LColor LStyle LWidth FFGColor FBGColor FPattern FMode"
q$ = Chr$(34)  ' a double quote
sp$ = Space$(1) ' a space
s1$ = "0 " + q$ + "Black" + q$ + sp$ + q$ + "Solid" + 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 include full file path and .lvl extension. For example: c:\temp\test.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
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))
	red$ = LTrim$(Str$(r))
	green$ = LTrim$(Str$(g))
	blue$ = LTrim$(Str$(b))
	Debug.Print contour(i);" ";red$;" "; green$;" "; blue$
	Print #1, contour(i);" ";s1$+"R"+red$+" G"+green$+" B"+blue$+s3$
Next 

For i = end1 + 1 To end2
	r = 0
	g = 255
	b = 255 - Int(255 / (end2 - end1) * (i - end1))
	red$ = LTrim$(Str$(r))
	green$ = LTrim$(Str$(g))
	blue$ = LTrim$(Str$(b))
	Debug.Print contour(i);" ";red$;" "; green$;" "; blue$
	Print #1, contour(i);" ";s1$+"R"+red$+" G"+green$+" B"+blue$+s3$
Next 

For i = end2 + 1 To end3
	b = 0
	g = 255
	r = Int(255 / (end3 - end2) * (i - end2))
	red$ = LTrim$(Str$(r))
	green$ = LTrim$(Str$(g))
	blue$ = LTrim$(Str$(b))
	Debug.Print contour(i);" ";red$;" "; green$;" "; blue$
	Print #1, contour(i);" ";s1$+"R"+red$+" G"+green$+" B"+blue$+s3$
Next 

For i = end3 + 1 To nlvls
	r = 255
	b = 0
	g = 255 - Int(255 / (nlvls - end3) * (i - end3))
	red$ = LTrim$(Str$(r))
	green$ = LTrim$(Str$(g))
	blue$ = LTrim$(Str$(b))
	Debug.Print contour(i);" ";red$;" "; green$;" "; blue$
	Print #1, contour(i);" ";s1$+"R"+red$+" G"+green$+" B"+blue$+s3$
Next 

Close #1
'LVL2

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

 

Updated February 14, 2017

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.