Microsoft Small Basic

Program Listing: DZC358
' Rainbow
' Copyright (c) 2012 Nonki Takahshi
'
width = 600 ' window width
height = 300 ' window height
x0 = 300 ' center of circle
y0 = 360 ' center of circle
r2 = 300 ' outer radius
r1 = 285 ' inner radius
h1 = 270 ' end of hue
s = Math.Ceiling(h1 / (r2 - r1))
GraphicsWindow.Width = width
GraphicsWindow.Height = height
GraphicsWindow.BackgroundColor = "gray"
num = Math.GetRandomNumber(2)
If num = 1 Then
tag = "sky"
Else ' num = 2
tag = "cloud"
EndIf
url = Flickr.GetRandomPicture(tag)
GraphicsWindow.DrawResizedImage(url, 0, 0, width, height)
For hue = 0 To h1 Step s
HueToColor()
DrawCircle()
r = r2 - Math.Floor((r2 - r1) * (hue / h1))
EndFor
' end of program

Sub HueToColor
' param hue - 0..360
' return color
If hue < 0 Then
red = 0
green = 0
blue = 0
ElseIf hue < 60 Then
red = 255
green = Math.Floor(hue / 59 * 255)
blue = 0
ElseIf hue < 120 Then
red = Math.Floor((59 - (hue - 60)) / 59 * 255)
green = 255
blue = 0
ElseIf hue < 180 Then
red = 0
green = 255
blue = Math.Floor((hue - 120) / 59 * 255)
ElseIf hue < 240 Then
red = 0
green = Math.Floor((59 - (hue - 180)) / 59 * 255)
blue = 255
ElseIf hue < 300 Then
red = Math.Floor((hue - 240) / 59 * 255)
green = 0
blue = 255
ElseIf hue < 360 Then
red = 255
green = 0
blue = Math.Floor((59 - (hue - 300)) / 59 * 255)
Else
red = 0
green = 0
blue = 0
EndIf
color = GraphicsWindow.GetColorFromRGB(red, green, blue)
EndSub

Sub DrawCircle
' param x0
' param y0
' param r
' param color
x = x0 - r
y = y0 - r
width = 2 * r
height = 2 * r
GraphicsWindow.PenColor = color
GraphicsWindow.DrawEllipse(x, y, width, height)
EndSub