Microsoft Small Basic

Program Listing: FBH659
' Curriculam 3.4 All shape version By NaochanON

GUI()
GraphicsWindow.MouseDown=OnmouseDown
GraphicsWindow.Mousemove = Paint

Sub onMouseDown
MX= GraphicsWindow.MouseX
MY= GraphicsWindow.MouseY
If 20 SHP_NMB=Math.Floor((MY-375)/40)+1 ' get shape number
cap= Rct[SHP_NMB]
Opacity()
Shapes.SetOpacity(srect1[SHP_NMB],80) ' show focused Shape
GraphicsWindow.PenColor=GraphicsWindow.GetRandomColor()
GraphicsWindow.BrushColor=GraphicsWindow.PenColor
EndIf
If 185 Act_NMB=Math.Floor((Mx-185)/100)+1 ' get action number
cap= Act[Act_NMB]
Opacity()
Shapes.SetOpacity(srect2[Act_NMB],80) ' show focused Action
EndIf
GraphicsWindow.Title=cap
If cap="Triangle" Then
z=1
Shapes.Remove(Shp[Z])
Shp[Z] = Shapes.AddTriangle(20,20,100,100,150,20)
Shapes.Move(Shp[Z],80,100)
ElseIf cap="Rectangle" then
z=2
Shapes.Remove(Shp[Z])
Shp[Z] = Shapes.AddRectangle(100,100)
Shapes.Move(Shp[Z],250,250)
elseif cap="Circle" then
Z=3
Shapes.Remove(Shp[Z])
Shp[Z]= Shapes.AddEllipse(100,100)
Shapes.Move(Shp[Z],400,150)
elseif cap="Zoom" or cap="Rotate" or cap="Clear" then
action()
elseif cap="Draw" then
i=0 ' not to zoom
Draw=1
GraphicsWindow.PenColor=GraphicsWindow.GetRandomColor()
elseif cap="Exit" then
Program.End()
EndIf
EndSub

Sub Opacity
For k=1 To 5
Shapes.SetOpacity(srect1[k],40)
Shapes.SetOpacity(srect2[k],40)
Endfor
EndSub

Sub action
If cap="Rotate" then
i=0 ' not to zoom
draw = 0 ' not to draw
m = m+30
Shapes.Rotate( Shp[Z], m)
elseIf cap="Zoom" then
draw = 0 ' not to draw
i =i+ 0.1
If i<0.4 Then
Shapes.Zoom(Shp[Z],1+i,1+i)
EndIf
elseIf cap="Clear" then
For j=1 To NN+3
Shapes.Remove(Shp[j]) ' erase Triangle, rectangle,Circle shapes
Shapes.Remove(Sln[j]) ' erase line shapes
EndFor
EndIf
EndSub

Sub Paint
If draw = 1 Then
GraphicsWindow.PenWidth = 5
x = GraphicsWindow.MouseX
y = GraphicsWindow.MouseY
If (10 If Mouse.IsLeftButtonDown Then
NN=NN+1
sln[NN]=Shapes.AddLine(orgx,orgy,x,y) ' add line shape
EndIf
EndIf
orgx = x
orgy = y
EndIf
EndSub

Sub GUI
GraphicsWindow.Width = 700
GraphicsWindow.Height = 500
GraphicsWindow.CanResize = "False"
GraphicsWindow.PenColor="Red"
GraphicsWindow.DrawRectangle(5,5,700,365)
GraphicsWindow.FontSize=20
'------------------------------- Shape name -----------------------------------------------
RCT="1=Rectangle;2=Circle;3=Triangle"
For i= 1 To Array.GetItemCount(Rct)
GraphicsWindow.BrushColor="Lightblue"
srect1[i]= Shapes.AddRectangle(120,35) ' Under rectangle
GraphicsWindow.BrushColor="Navy"
srct[i]=Shapes.AddText(rct[i]) ' Top Shape name
Shapes.Move(srect1[i],20,375+(i-1)*40)
Shapes.Move(srct[i],25,380+(i-1)*40)
EndFor
'----------------------------- Action name-------------------------------------------------
Act="1=Zoom;2=Rotate;3=Draw;4=Clear;5=Exit"
For i= 1 To Array.GetItemCount(Act)
GraphicsWindow.BrushColor="Lightblue"
srect2[i]= Shapes.AddRectangle(95,35) ' Under rectangle
GraphicsWindow.BrushColor="Navy"
sact[i]=Shapes.AddText(Act[i]) ' Top Action name
Shapes.Move(srect2[i],185+(i-1)*100,415)
Shapes.Move(sact[i],200+(i-1)*100,420)
EndFor
'----------------------------- Set Opacity light color -------------------------------------
Opacity()
EndSub