Microsoft Small Basic

Program Listing: KFJ748-2
' Wood Grain
' Version 0.4
' Copyright © 2014-2015 Nonki Takahashi. The MIT License.
' Last update 2015-11-15
' Program ID KFJ748-2
'
GraphicsWindow.Title = "Wood Grain 0.4"
gw = 600
gh = 600
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
xo = 420
yo = 640
dark = "#EEBB66"
light = "#FFDD88"
GraphicsWindow.BackgroundColor = dark
d = 7
ratio = 14 ' vertical / horizontal
For y = 0 To gh - 1
For x = 0 To gw - 1
GetColor()
GraphicsWindow.SetPixel(x, y, medium)
EndFor
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)
half = d / 2
If "True" Then
p = Math.Floor((1 - Math.Power(r / half - 1, 2)) * 100)
Else
If r < half Then
p = Math.Floor(r / half * 100)
Else
p = Math.Floor((d - r) / half * 100)
EndIf
EndIf
MediumColor()
GraphicsWindow.PenColor = medium
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)
Math_Hex2Dec()
a = dec
hex = Text.GetSubText(light, i * 2, 2)
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