Microsoft Small Basic

Program Listing: TFC068
'Published as
'Hint: you will need to use Timer, GraphicsWindow, ProgramWindow,
'ColorWheel, ShapeMaker, and Shapes.

'PrepareBubbleWand (recipe below)
PrepareBubbleWand()
'Set the timer to call the BubbleMaker (recipe below) at each tick
Timer.Tick = BubbleMaker
'Make the interval on the timer 100 ms
Timer.Start(100)


'------------- Recipe for PrepareBubbleWand
Sub PrepareBubbleWand
' This program has 15 bubbles
numberBubbles = 15
' The fade factor is 100% / the number of bubbles
fadeFactor = 100/numberBubbles
' PrepareColorPalette (recipe below)
PrepareColorPalette()
'------------- End of PrepareBubbleWand recipe
EndSub

'------------- Recipe for PrepareColorPalette
Sub PrepareColorPalette
' Add alice blue to the color wheel
ColorWheel.AddColor(Colors.AliceBlue)
' Add blue to the color wheel
ColorWheel.AddColor(Colors.Blue)
' Add dark blue to the color wheel
ColorWheel.AddColor(Colors.DarkBlue)
' Add purple to the color wheel
ColorWheel.AddColor(Colors.Purple)
'------------- End of PrepareColorPalette recipe
EndSub

'------------- Recipe for BubbleMaker
Sub BubbleMaker
' The number of new bubbles created is zero
newBubbles = 0
' Do the following for each bubble
For i = 1 To numberBubbles
' If the opacity of the current bubble is less than zero, then
If opacity[i] < 0 Then
' CreateBubble (recipe below)
CreateBubble()
' Otherwise
Else
' FadeBubble (recipe below)
FadeBubble()
EndIf
Endfor
' Repeat
EndSub
'------------- End of BubbleMaker recipe


'------------- Recipe for FadeBubble
Sub FadeBubble
' Reduce the opacity of the current bubble by the fade factor
opacity[i] = opacity[i] - fadeFactor
' Sync the opacity of the current bubble
ShapeMaker.SetOpacity(bubbles[i],opacity[i])
'------------- End of FadeBubble recipe
EndSub

'------------- Recipe for CreateBubble
Sub CreateBubble
' If no new bubbles have been created, then
If (newBubbles = 0) Then
' Remove the current bubble
ShapeMaker.RemoveShape(bubbles[i])
' Change the color for the new bubble to be the next color on the color wheel
ShapeMaker.SetColorForNextShape(ColorWheel.GetNextColor())
' The opacity of the new bubble is 100%
opacity[i] = 100
' The radius of the new bubble is a random number between 10 and 50 pixels
radius = Math.GetRandomNumber(40)+10
' Create a new bubble
bubbles[i] = ShapeMaker.CreateCircle(radius)
' Center the bubble at the location of the mouse in the program window
ShapeMaker.CenterShapeAt(bubbles[i], ProgramWindow.GetMouseX(), ProgramWindow.GetMouseY())
' Increment the number of new bubbles created
newBubbles = newBubbles + 1
EndIf
'------------- End of CreateBubble recipe
EndSub