locked
Delete Paintings "Addon" RRS feed

  • General discussion

  • im new to programming&so on and its just my 2nd day im doing this so dont be that hard :P

    GraphicsWindow.Title = "Paint Program"
    GraphicsWindow.KeyUp = OnKeyUp
    GraphicsWindow.BrushColor = "Black"
    GraphicsWindow.KeyDown = OnKeyDown
    GraphicsWindow.MouseMove = OnMouseMove
    GraphicsWindow.MouseDown = OnMouseDown

    Sub OnMouseDown
        x = GraphicsWindow.MouseX
        y = GraphicsWindow.MouseY
        GraphicsWindow.DrawLine(prevX, prevY, x, y)
        prevX = x
        prevY = y
    EndSub

    Sub OnKeyDown
        brushcolor = GraphicsWindow.GetRandomColor()
        GraphicsWindow.BrushColor = brushcolor
    EndSub

    Sub OnMouseMove
        x = GraphicsWindow.MouseX
        y = GraphicsWindow.MouseY
        If (Mouse.IsLeftButtonDown) Then
            GraphicsWindow.DrawLine(prevX, prevY, x, y)
        EndIf
        prevX = x
        prevY = y
    EndSub

    Sub OnKeyUp
        GraphicsWindow.Clear()
    EndSub

    this is the "normal" paint which was described in the introduction, but ive added this:

    GraphicsWindow.KeyUp = OnKeyUp
    ...
    Sub OnKeyUp
        GraphicsWindow.Clear()
    EndSub

    when you hit any key and then "up" the key the whole image gets deleted, may thats intresting for some other beginners here too :)

    Tuesday, November 25, 2008 2:21 PM

All replies

  • Here is my crappy 3am version :)

    commandList()
    GraphicsWindow.MouseMove = onMouseMove
    GraphicsWindow.MouseDown = onMouseDown
    GraphicsWindow.KeyDown = onKeyDown

    penSize = GraphicsWindow.PenWidth
    penColour = GraphicsWindow.PenColor

    colourOne = "green"
    colourTwo = "blue
    colourThree = "yellow"
    colourFour = "red"
    colourFive = "pink"
    colourSix = "brown"
    colourSeven = "purple"
    colourEight = "cyan"
    colourNine = "chartreuse"
    colourZero = "black"

    Sub onKeyDown
        lastKey = GraphicsWindow.LastKey
        
        If (lastKey = "R") Then
            TextWindow.WriteLine("Would you like to turn rainbow on (y) or off (n) (y/n)")
            lastKey = TextWindow.Read()
            If (lastKey = "y") Then
                rainbowOn = "y"
            Else
                rainbowOn = "n"
            EndIf
        EndIf
       
        If (lastKey = "E") Then
            TextWindow.WriteLine("This lets you edit the current colour presets.")
            TextWindow.WriteLine("Currently they are:")
            TextWindow.WriteLine("1: " + colourOne)
            TextWindow.WriteLine("2: " + colourTwo)
            TextWindow.WriteLine("3: " + colourThree)
            TextWindow.WriteLine("4: " + colourFour)
            TextWindow.WriteLine("5: " + colourFive)
            TextWindow.WriteLine("6: " + colourSix)
            TextWindow.WriteLine("7: " + colourSeven)
            TextWindow.WriteLine("8: " + colourEight)
            TextWindow.WriteLine("9: " + colourNine)
            TextWindow.WriteLine("0: " + colourZero)
            TextWindow.WriteLine("Please input the preset you would like to edit. (0-9)")
            lastKey = TextWindow.ReadNumber()
           
            If (lastKey = ".") Then
                TextWindow.WriteLine("You have canceled.")
            EndIf
           
            If (lastKey = 1) Then
                TextWindow.WriteLine("Please input the colour you would like to change preset " + lastKey + " to. (#FFFFFF or name)")      
                colourOne = TextWindow.Read()
                If (colourOne = ".") Then
                    TextWindow.WriteLine("You have canceled.")
                Else
                    TextWindow.WriteLine("Preset " + lastKey + " is now " + colourOne + ".")
                EndIf
            EndIf
           
            If (lastKey = 2) Then
                TextWindow.WriteLine("Please input the colour you would like to change preset " + lastKey + " to. (#FFFFFF or name)")      
                colourTwo = TextWindow.Read()
                If (colourTwo = ".") Then
                    TextWindow.WriteLine("You have canceled.")
                Else
                    TextWindow.WriteLine("Preset " + lastKey + " is now " + colourOne + ".")
                EndIf
            EndIf
           
            If (lastKey = 3) Then
                TextWindow.WriteLine("Please input the colour you would like to change preset " + lastKey + " to. (#FFFFFF or name)")      
                colourThree = TextWindow.Read()
                If (colourThree = ".") Then
                    TextWindow.WriteLine("You have canceled.")
                Else
                    TextWindow.WriteLine("Preset " + lastKey + " is now " + colourOne + ".")
                EndIf
            EndIf
           
            If (lastKey = 4) Then
                TextWindow.WriteLine("Please input the colour you would like to change preset " + lastKey + " to. (#FFFFFF or name)")      
                colourFour = TextWindow.Read()
                If (colourFour = ".") Then
                    TextWindow.WriteLine("You have canceled.")
                Else
                    TextWindow.WriteLine("Preset " + lastKey + " is now " + colourOne + ".")
                EndIf
            EndIf
           
            If (lastKey = 5) Then
                TextWindow.WriteLine("Please input the colour you would like to change preset " + lastKey + " to. (#FFFFFF or name)")      
                colourFive = TextWindow.Read()
                If (colourFive = ".") Then
                    TextWindow.WriteLine("You have canceled.")
                Else
                    TextWindow.WriteLine("Preset " + lastKey + " is now " + colourOne + ".")
                EndIf
            EndIf
           
            If (lastKey = 6) Then
                TextWindow.WriteLine("Please input the colour you would like to change preset " + lastKey + " to. (#FFFFFF or name)")      
                colourSix = TextWindow.Read()
                If (colourSix = ".") Then
                    TextWindow.WriteLine("You have canceled.")
                Else
                    TextWindow.WriteLine("Preset " + lastKey + " is now " + colourOne + ".")
                EndIf
            EndIf
           
            If (lastKey = 7) Then
                TextWindow.WriteLine("Please input the colour you would like to change preset " + lastKey + " to. (#FFFFFF or name)")      
                colourSeven = TextWindow.Read()
                If (colourSeven = ".") Then
                    TextWindow.WriteLine("You have canceled.")
                Else
                    TextWindow.WriteLine("Preset " + lastKey + " is now " + colourOne + ".")
                EndIf
            EndIf
           
            If (lastKey = 8) Then
                TextWindow.WriteLine("Please input the colour you would like to change preset " + lastKey + " to. (#FFFFFF or name)")      
                colourEight = TextWindow.Read()
                If (colourEight = ".") Then
                    TextWindow.WriteLine("You have canceled.")
                Else
                    TextWindow.WriteLine("Preset " + lastKey + " is now " + colourOne + ".")
                EndIf
            EndIf
           
            If (lastKey = 9) Then
                TextWindow.WriteLine("Please input the colour you would like to change preset " + lastKey + " to. (#FFFFFF or name)")
                colourNine = TextWindow.Read()
                If (colourNine = ".") Then
                    TextWindow.WriteLine("You have canceled.")
                Else
                    TextWindow.WriteLine("Preset " + lastKey + " is now " + colourOne + ".")
                EndIf
            EndIf
           
            If (lastKey = 0) Then
                TextWindow.WriteLine("Please input the colour you would like to change preset " + lastKey + " to. (#FFFFFF or name)")      
                colourZero = TextWindow.Read()
                If (colourZero = ".") Then
                    TextWindow.WriteLine("You have canceled.")
                Else
                    TextWindow.WriteLine("Preset " + lastKey + " is now " + colourOne + ".")
                EndIf
            EndIf
        EndIf
       
        If (lastKey = "D1") Then
            GraphicsWindow.PenColor = colourOne
        EndIf
       
        If (lastKey = "D2") Then
            GraphicsWindow.PenColor = colourTwo
        EndIf
       
        If (lastKey = "D3") Then
            GraphicsWindow.PenColor = colourThree
        EndIf
       
        If (lastKey = "D4") Then
            GraphicsWindow.PenColor = colourFour
        EndIf
       
        If (lastKey = "D5") Then
            GraphicsWindow.PenColor = colourFive
        EndIf
       
       
        If (lastKey = "D6") Then
            GraphicsWindow.PenColor = colourSix
        EndIf
       
        If (lastKey = "D7") Then
            GraphicsWindow.PenColor = colourSeven
        EndIf
       
        If (lastKey = "D8") Then
            GraphicsWindow.PenColor = colourEight
        EndIf
       
        If (lastKey = "D9") Then
            GraphicsWindow.PenColor = colourNine
        EndIf
       
        If (lastKey = "D0") Then
            GraphicsWindow.PenColor = colourZero
        EndIf
       
        If (lastKey = "C") then
            TextWindow.WriteLine("Current penColour is " + penColour + ".")
            TextWindow.WriteLine("Please input new penColour. (#FFFFFF or name)")
            penColour = TextWindow.Read()
            If (penColour = ".") Then
                TextWindow.WriteLine("You have canceled.")
            Else
                GraphicsWindow.PenColor = penColour        
            EndIf
        EndIf
       
        If (lastKey = "S") Then
            TextWindow.WriteLine("Current penSize is " + penSize + ".")
            TextWindow.WriteLine("Please input new penSize. (1-9)")
            penSize = TextWindow.ReadNumber()
            If (penSize = ".") Then
                TextWindow.WriteLine("You have canceled.")
            Else
                GraphicsWindow.PenWidth = penSize      
            EndIf       
        Endif
       
        If (lastKey = "V") Then
            TextWindow.WriteLine("This lets you edit the current colour presets.")
            TextWindow.WriteLine("Currently they are:")
            TextWindow.WriteLine("1: " + colourOne)
            TextWindow.WriteLine("2: " + colourTwo)
            TextWindow.WriteLine("3: " + colourThree)
            TextWindow.WriteLine("4: " + colourFour)
            TextWindow.WriteLine("5: " + colourFive)
            TextWindow.WriteLine("6: " + colourSix)
            TextWindow.WriteLine("7: " + colourSeven)
            TextWindow.WriteLine("8: " + colourEight)
            TextWindow.WriteLine("9: " + colourNine)
            TextWindow.WriteLine("0: " + colourZero)
        EndIf
       
        If (lastKey = "L") Then
            TextWindow.WriteLine("Are you sure you want to clear the screen? (y/n)")
            lastKey = TextWindow.Read()
            If (lastKey = "N") Then
                TextWindow.WriteLine("You have canceled.")
            Else
                GraphicsWindow.Clear()
                TextWindow.WriteLine("Screen cleared")
            EndIf
        EndIf
       
        If (lastKey = "B") Then
            TextWindow.WriteLine("Current Background colour is " + GraphicsWindow.BackgroundColor + ".")
            TextWindow.WriteLine("Please input new Background Colour (#FFFFFF)")
            bgColour = TextWindow.Read()
            If (bgColour = ".") Then
                TextWindow.WriteLine("You have canceled.")
            Else
                GraphicsWindow.BackgroundColor = bgColour
            EndIf
        EndIf
       
        If (lastKey = "H") Then
            commandList()
        EndIf
    EndSub   

    Sub onMouseDown
        prevX = GraphicsWindow.MouseX
        prevY = GraphicsWindow.MouseY
    EndSub

    Sub onMouseMove
        xCoord = GraphicsWindow.MouseX
        yCoord = GraphicsWindow.MouseY
        If (Mouse.IsLeftButtonDown) Then
            GraphicsWindow.DrawLine(prevX, prevY, xCoord, yCoord)
            If (rainbowOn = "y") then
                penColour = GraphicsWindow.GetRandomColor()
                GraphicsWindow.PenColor = penColour
            EndIf
        EndIf
        prevX = xCoord  
        prevY = yCoord
    EndSub

    sub commandList
        TextWindow.WriteLine("Paint clone commands list:")
        TextWindow.WriteLine("S to change penSize.")
        TextWindow.WriteLine("C to change penColour.")
        TextWindow.WriteLine("B to change Background colour.")
        TextWindow.WriteLine("H to reprint this list at any time. (Help)")
        TextWindow.WriteLine(". to cancel any selected command.")
        TextWindow.WriteLine("L to cLear the screen. ")
        TextWindow.WriteLine("V to View preset pen colours.")
        TextWindow.WriteLine("E to Edit preset pen colours.")
        TextWindow.WriteLine("R to use experimental rainbow pen colour.")
    EndSub



    I'd like to add an actual UI in so I'm working on that.
    Tuesday, November 25, 2008 3:12 PM