Microsoft Small Basic

Program Listing:
Embed this in your website
'Logic by Jibba Jabba
'I, Josh Miedema, added some things: Clear, change colour, change mirror, and eraser, as well as expanding on the amount of available mirrors.
'I am also planning on adding the ability to mirror vertically as well as horizontally at the same time. Maybe even the two diagonals, too! We'll see.


'Set the Eraser Function to False because you can't draw with an eraser:P
Eraser = "False"

'Run Subroutines
'-Debugger console (also handles the getting of info: colours and mirror position)
DEBUG()
'-Gets the type of mirror to use (using the debugger)
GetMirrorPos()
'-Gets colours (Leave blank to use defaults) (also uses debugger)
GetColours()
'-This sets up the graphics window
Initialise()

'Register Events
GraphicsWindow.MouseMove = OnMouseMove
Controls.ButtonClicked = ButtonClick

'======================================================
'|| Game Loop ||
'======================================================
While "True"
  start = Clock.ElapsedMilliseconds

  'Update Program
  If mouseMoving And Mouse.IsLeftButtonDown = "True" Then
    X = GraphicsWindow.MouseX
    Y = GraphicsWindow.MouseY
    mouseMoving = "False"
  EndIf

  'Update Frame
  '-Removes the mirror line (Helps for the "Change Mirror" button)
  Shapes.Remove(Mirror)
  '-Resets background colour (Helps for the "Change Colour" button
  GraphicsWindow.BackgroundColor = BackgroundColour

  '-Checks that the Eraser state is set to false...
  If Eraser = "False" Then
    '...So it can use normal colours.
    GraphicsWindow.PenColor = OriginalColour
    GraphicsWindow.DrawEllipse(X, Y, 3, 3)
    'This IF statement will determine where the copies will be drawn depending on what mirror the user chose.
    If Option = "1" Then
      GraphicsWindow.PenColor = MirrorColour
      Mirror = Shapes.AddLine(0, 250, 500, 250)
      GraphicsWindow.PenColor = CopyColour
      GraphicsWindow.DrawEllipse(X, gh-Y, 3, 3)
    ElseIf Option = "2" Then
      GraphicsWindow.PenColor = MirrorColour
      Mirror = Shapes.AddLine(250, 0, 250, 500)
      GraphicsWindow.PenColor = CopyColour
      GraphicsWindow.DrawEllipse(gw-X, Y, 3, 3)
    ElseIf Option = "3" Then
      GraphicsWindow.PenColor = MirrorColour
      Mirror = Shapes.AddLine(0, 0, 500, 500)
      GraphicsWindow.PenColor = CopyColour
      GraphicsWindow.DrawEllipse(Y, X, 3, 3)
    ElseIf Option = "4" Then
      GraphicsWindow.PenColor = MirrorColour
      Mirror = Shapes.AddLine(500, 0, 0, 500)
      GraphicsWindow.PenColor = CopyColour
      GraphicsWindow.DrawEllipse(gw-Y, gh-X, 3, 3)
    ElseIf Option = "5" Then
      GraphicsWindow.PenColor = MirrorColour
      Mirror = Shapes.AddLine(0, 250, 500, 250)
      GraphicsWindow.PenColor = CopyColour
      GraphicsWindow.DrawEllipse(X/2+125, gh-Y/2-125, 3, 3)
    ElseIf Option = "6" Then
      GraphicsWindow.PenColor = MirrorColour
      Mirror = Shapes.AddLine(250, 0, 250, 500)
      GraphicsWindow.PenColor = CopyColour
      GraphicsWindow.DrawEllipse(gw-X/2-125, Y/2+125, 3, 3)
    EndIf
    'But if the eraser is turned on, adjust all colours to be the background colour.
  ElseIf Eraser = "True" Then
    GraphicsWindow.PenColor = GraphicsWindow.BackgroundColor
    GraphicsWindow.DrawEllipse(X, Y, 7, 7)
    'Again, this will determine where the copies will be placed. This time for the eraser.
    If Option = "1" Then
      GraphicsWindow.PenColor = MirrorColour
      Mirror = Shapes.AddLine(0, 250, 500, 250)
      GraphicsWindow.PenColor = GraphicsWindow.BackgroundColor
      GraphicsWindow.DrawEllipse(X, gh-Y, 7, 7)
    ElseIf Option = "2" Then
      GraphicsWindow.PenColor = MirrorColour
      Mirror = Shapes.AddLine(250, 0, 250, 500)
      GraphicsWindow.PenColor = GraphicsWindow.BackgroundColor
      GraphicsWindow.DrawEllipse(gw-X, Y, 7, 7)
    ElseIf Option = "3" Then
      GraphicsWindow.PenColor = MirrorColour
      Mirror = Shapes.AddLine(0, 0, 500, 500)
      GraphicsWindow.PenColor = GraphicsWindow.BackgroundColor
      GraphicsWindow.DrawEllipse(Y, X, 7, 7)
    ElseIf Option = "4" Then
      GraphicsWindow.PenColor = MirrorColour
      Mirror = Shapes.AddLine(500, 0, 0, 500)
      GraphicsWindow.PenColor = GraphicsWindow.BackgroundColor
      GraphicsWindow.DrawEllipse(gw-Y, gh-X, 7, 7)
    ElseIf Option = "5" Then
      GraphicsWindow.PenColor = MirrorColour
      Mirror = Shapes.AddLine(0, 250, 500, 250)
      GraphicsWindow.PenColor = GraphicsWindow.BackgroundColor
      GraphicsWindow.DrawEllipse(X/2+125, gh-Y/2-125, 7, 7)
    ElseIf Option = "6" Then
      GraphicsWindow.PenColor = MirrorColour
      Mirror = Shapes.AddLine(250, 0, 250, 500)
      GraphicsWindow.PenColor = GraphicsWindow.BackgroundColor
      GraphicsWindow.DrawEllipse(gw-X/2-125, Y/2+125, 7, 7)
    EndIf
  EndIf


  'Constant Frame Rate of 1000/10 per second. That's a whopping 100 FPS --> YAY! Thanks!
  delay = 10 - (Clock.ElapsedMilliseconds - start)
  If delay > 0 Then
    TextWindow.WriteLine("updates < 10ms")
    Program.Delay(delay)
  Else
    'I added this just because I wanted to see how often it'd show, but it flashes for the briefest time!
    TextWindow.WriteLine("updates > 10ms")
  EndIf
EndWhile

'===================================================
'Event Subroutines
'===================================================
'Mouse Move
Sub OnMouseMove
  mouseMoving = "True"
EndSub

'Button Click
Sub ButtonClick
  'This IF statement checks what the last button was
  '-Clear Button
  If Controls.LastClickedButton = Clear Then
    'Clear window and re-add buttons
    GraphicsWindow.Clear()
    Clear = Controls.AddButton("Clear", 0, 500)
    Controls.SetSize(Clear, 50, 30)
    ChangeMirror = Controls.AddButton("Change Mirror", 50, 500)
    Controls.SetSize(ChangeMirror, 100, 30)
    ChangeColours = Controls.AddButton("Change Colours", 150, 500)
    Controls.SetSize(ChangeColours, 100, 30)
    EraserButton = Controls.AddButton("Eraser Off", 250, 500)
    Controls.SetSize(EraserButton, 150, 30)

    '-Change Mirror Button
  ElseIf Controls.LastClickedButton = ChangeMirror Then
    GetMirrorPos()

    '-Change Colours Button
  ElseIf Controls.LastClickedButton = ChangeColours Then
    GetColours()

    '-Eraser Button
  ElseIf Controls.LastClickedButton = EraserButton Then
    'Checks the state of the eraser when the button is clicked
    '-If the eraser was enabled when the button was clicked, turn it off
    If Eraser = "True" Then
      Eraser = "False"
      'And set the button caption to off
      Controls.SetButtonCaption(EraserButton, "Eraser Off")
      '-If the eraser was disabled when the button was clicked, turn it on
    ElseIf Eraser = "False" Then
      Eraser = "True"
      'And set the button caption to on
      Controls.SetButtonCaption(EraserButton, "Eraser On")
    EndIf
  EndIf
EndSub


'===================================================
'Other Subroutines
'===================================================
Sub Initialise
  'Fairly straight forward here...
  GraphicsWindow.Title = "Drawing Mirror"
  gw = 500
  gh = 500
  GraphicsWindow.Width = gw
  GraphicsWindow.Height = gh + 30
  GraphicsWindow.Top = 10'(Desktop.Height - 500)/2
  GraphicsWindow.Left = (Desktop.Width - gw)/2+50
  GraphicsWindow.BackgroundColor = BackgroundColour
  GraphicsWindow.Clear()
  Clear = Controls.AddButton("Clear", 0, 500)
  Controls.SetSize(Clear, 50, 30)
  ChangeMirror = Controls.AddButton("Change Mirror", 50, 500)
  Controls.SetSize(ChangeMirror, 100, 30)
  ChangeColours = Controls.AddButton("Change Colours", 150, 500)
  Controls.SetSize(ChangeColours, 100, 30)
  EraserButton = Controls.AddButton("Eraser Off", 250, 500)
  Controls.SetSize(EraserButton, 150, 30)
EndSub

'Sets up the debug console (also used to ask user for mirror type and colours)
Sub DEBUG
  TextWindow.Left = 20
  TextWindow.Top = gh + 20
EndSub

'Asks the user for the mirror type using debug console
Sub GetMirrorPos
  TextWindow.Clear()
  Program.Delay(10)
  TextWindow.WriteLine("[1] Horizontal Mirror")
  TextWindow.WriteLine("[2] Vertical Mirror")
  TextWindow.WriteLine("[3] Diagonal Mirror (Top Left to Bottom Right)")
  TextWindow.WriteLine("[4] Diagonal Mirror (Top Right to Bottom Left)")
  TextWindow.WriteLine("[5] Draw Half-Scale on Horizontal Mirror")
  TextWindow.WriteLine("[6] Draw Half-Scale on Vertical Mirror")
  TextWindow.Write("--> ")
  Option = TextWindow.Read()
EndSub

'Asks the user for the colours to use using the debug console
Sub GetColours
  TextWindow.Clear()
  Program.Delay(10)
  'Asks for background colour:
  TextWindow.Write("Background Colour: ")
  BackgroundColour = TextWindow.Read()
  'This IF statement checks the background colour Var. to see if it's empty. If so, set it to my default
  If BackgroundColour = "" Then
    BackgroundColour = "Black"
  EndIf
  'Asks for the "Original Colour" whick is the one the user draws with
  TextWindow.Write("Original Colour: ")
  OriginalColour = TextWindow.Read()
  'This IF statement checks the original colour Var. to see if it's empty. If so, set it to my default
  If OriginalColour = "" Then
    OriginalColour = "Yellow"
  EndIf
  'Asks for the "Copy" colour which is the one that the computer uses to draw mirror (using mirror type)
  TextWindow.Write("Copy Colour: ")
  CopyColour = TextWindow.Read()
  'This IF statement checks the copy colour Var. to see if it's empty. If so, set it to my default
  If CopyColour = "" Then
    CopyColour = "Green"
  endIf
  'Asks for the mirror colour which is the colour used to show the mirror line. Kind of a bad name to use because people might think it's for the mirror drawing...
  TextWindow.Write("Mirror Colour: ")
  MirrorColour = TextWindow.Read()
  'This IF statement checks the mirror colour Var. to see if it's empty. If so, set it to my default
  If MirrorColour = "" Then
    MirrorColour = "Gray"
  EndIf
EndSub
Copyright (c) Microsoft Corporation. All rights reserved.