Microsoft Small Basic

Program Listing: LPR683-0
' Wood Bookshelfs
' Copyright © 2014 Nonki Takahashi & qwix. All rights reserved.
' Last update 2014-11-26
'
GraphicsWindow.Title = "Wood Bookshelfs"
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
by=30
For bx=0 to 1000 step 500
bshelf()
endfor

Sub bshelf

d = 7
ii=0
half = d / 2
h1=100/half
t30=227
For x=1 to 10
w[x]= Math.GetRandomNumber(5)+1
endfor

ratio = 5 ' vertical / horizontal
For y = gh-150 To 0 Step -6

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

GraphicsWindow.PenColor =medium
GraphicsWindow.PenWidth=w[z*2+1]
GraphicsWindow.DrawLine (bx+gw2+x-15-w250, by+y-10, bx+gw2+x-w250,by+y)
endfor
endfor

For y = 0 To gh/2 Step 6

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

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

endfor

EndFor
ii=ii+3
EndFor

For y = gh-150 To 0 Step -6

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

GraphicsWindow.PenColor =medium
GraphicsWindow.PenWidth=w[z*2+1]
GraphicsWindow.DrawLine (bx+gw2+x-15-w250+230, by+y-10+230, bx+gw2+x-w250+230,by+y+230)
endfor
endfor
EndSub

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