Microsoft Small Basic

Program Listing: XQW156-0
' 3D Wood Grain
' Copyright © 2014 Nonki Takahashi and qwix. All right reserved.
' Last update 2014-11-26
'
GraphicsWindow.Title = "3D Wood Grain"
gw = 450
w250=300
gw2=(gw-w250)-20
gh = 900
GraphicsWindow.Width = 1500
GraphicsWindow.Height = gh
xo = 400
yo = 400
dark = "#CC8833"
light = "#FFCC66"
GraphicsWindow.BackgroundColor = dark
d = 7
ii=0
half = d / 2
h1=100/half
t30=77
For x=1 to 10
w[x]= Math.GetRandomNumber(5)+1
endfor

ratio = 5 ' vertical / horizontal
For y = 0 To gh*1.2 Step 6

For x = w250 To gw - 1 Step 4
GetColor()

GraphicsWindow.PenColor =medium
For z=0 to 4
GraphicsWindow.PenWidth=w[z*2+1]
GraphicsWindow.DrawLine (z*gw2+x-w250+ii, y/2+(4-z)*t30, z*gw2+x-3+ii-w250,y/2+25+(4-z)*t30)
'GraphicsWindow.PenWidth=w[z*2+2]
'GraphicsWindow.DrawLine (z*gw2+gw*2-x-w250, y, z*gw2+gw*2-x-3-w250,y+5)
endfor

EndFor
ii=ii+3
EndFor
Sub GetColor
' param x, y - point to get color
nx = x - xo
ny = (y - yo) / ratio
r = Math.Remainder(Math.SquareRoot(nx * nx + ny * ny), d)

If r < half Then
p = Math.Floor(r*h1)
MediumColor()
GraphicsWindow.PenColor = medium
Else
p = Math.Floor((d - r) *h1)
MediumColor()
GraphicsWindow.PenColor = medium
EndIf
EndSub
Sub MediumColor
' param dark, light - given colors
' param p - percentage
' return medium - medium color
For i = 1 To 3
hex = Text.GetSubText(dark, i * 2, 2)

'a = ESLMaths.HexToInteger (hex)
Math_Hex2Dec()
a = dec
hex = Text.GetSubText(light, i * 2, 2)

'b = ESLMaths.HexToInteger (hex)
Math_Hex2Dec()
b = dec
v[i] = Math.Floor(a * (1 - p / 100) + b * p / 100)
EndFor
medium = GraphicsWindow.GetColorFromRGB(v[1], v[2], v[3])
EndSub
Sub Math_Hex2Dec
' Math | Convert hexadecimal to decimal
' param hex - hexadecimal
' return dec - decimal
dec = 0
len = Text.GetLength(hex)
For ptr = 1 To len
dec = dec * 16 + Text.GetIndexOf("0123456789ABCDEF", Text.GetSubText(hex, ptr, 1)) - 1
EndFor
EndSub