
-----------------------------------
Kaykao
Fri Feb 22, 2013 4:40 pm

My First Three Programs - details inside
-----------------------------------
Hello there!

I'm not very experienced with turing yet, but I figured I would share the first three little programs I've made. Please, tell me what you think! If the code could be shortened or I've made an error, or something could in any way be improved on any of these programs, I'd love to hear it.

I'm now attempting to make a simple calculator, but I'm searching for other simple little projects to do to help expand my knowledge of the program. So feel free to suggest little projects I could tackle if you feel like it.

And I apologize for this thread being so long... I didn't know how else to put these up. >>;

Math Practice - A program that asks the user a simple math question, and will tell the user if the answer they give is right or wrong.
I did my best to work out the bugs with division... But there might still be something. Eheh.
Guess The Number - A very simple game that asks the user to guess a number between 1 and 10. If the user doesn't guess right on the first try, the program will tell them whether they need to guess higher or lower. It generates a new number every play through, and you can either quit or choose to play another round after each guessed number.
I was thinking of limiting how many guesses you have before you fail somehow... perhaps using a for loop? What do you think?

Paint Rip-Off - This program lets you draw lines within the bordered area. You can pick from a few different pencil colours and sizes for your drawing, and clear the canvas if you for some reason wish to murder your obviously beautiful creation.
Man did this one ever take some figuring out... And I know it doesn't have all the tools MS Paint has, I just couldn't think up a better name for it.
[Code]%-----VARIABLES-----%

var windowID := Window.Open ("graphics:500;400")
var x, y, x2, y2, x3, y3, button, count, LineColour, LineThickness : int
LineColour := 7
LineThickness := 2
var mode : string := "pencil"
View.Set ("graphics")
buttonchoose ("multibutton")

%-----PROCEDURES-----%

procedure ColourPicker
    Mouse.Where (x3, y3, button)
    if x3 < 30 and x3 > 20 and y3 < 270 and y3 > 260 and buttonmoved ("downup") then
        LineColour := 7
    elsif x3 < 30 and x3 > 20 and y3 < 290 and y3 > 280 and buttonmoved ("downup") then
        LineColour := 12
    elsif x3 < 30 and x3 > 20 and y3 < 310 and y3 > 300 and buttonmoved ("downup") then
        LineColour := 32
    elsif x3 < 30 and x3 > 20 and y3 < 330 and y3 > 320 and buttonmoved ("downup") then
        LineColour := 10
    elsif x3 < 30 and x3 > 20 and y3 < 250 and y3 > 240 and buttonmoved ("downup") then
        LineColour := 31
    end if
end ColourPicker

procedure clear
    for a : 91 .. 579     %Draws white lines across the screen from left to right to clear it
        delay (1)
        Draw.Line (a, 41, a, 349, white)
    end for
end clear

procedure QuitButton
    Mouse.Where (x3, y3, button)
    if x3 < 70 and x3 > 10 and y3 < 40 and y3 > 10 and buttonmoved ("downup") then
        Window.Close (windowID)
    end if
end QuitButton

procedure PencilSizePicker
    Mouse.Where (x3, y3, button)
    if x3 < 12 and x3 > 8 and y3 < 377 and y3 > 373 and buttonmoved ("downup") then
        LineThickness := 2
    elsif x3 < 33 and x3 > 27 and y3 < 378 and y3 > 372 and buttonmoved ("downup") then
        LineThickness := 4
    elsif x3 < 54 and x3 > 46 and y3 < 379 and y3 > 371 and buttonmoved ("downup") then
        LineThickness := 6
    elsif x3 < 75 and x3 > 65 and y3 < 380 and y3 > 370 and buttonmoved ("downup") then
        LineThickness := 8
    elsif x3 < 96 and x3 > 84 and y3 < 381 and y3 > 369 and buttonmoved ("downup") then
        LineThickness := 10
    end if
end PencilSizePicker

%----COLOUR PICKER-----%
Text.Locate (4, 1)
put "Colour:"
Draw.Box (20, 240, 30, 250, 7) % white (eraser)
Draw.FillBox (20, 260, 30, 270, 7) % black
Draw.FillBox (20, 280, 30, 290, 12) % red
Draw.FillBox (20, 300, 30, 310, 32) % blue
Draw.FillBox (20, 320, 30, 330, 10) % green

%-----PENCIL SIZE PICKER-----%
Text.Locate (1, 1)
put "Size:":30, "Left click to draw, right click to clear canvas."
Draw.FillOval (10, 375, 2, 2, 7) % size 1
Draw.FillOval (30, 375, 3, 3, 7) % size 2
Draw.FillOval (50, 375, 4, 4, 7) % size 3
Draw.FillOval (70, 375, 5, 5, 7) % size 4
Draw.FillOval (90, 375, 6, 6, 7) % size 5

%-----QUIT BUTTON-----%
Text.Locate (24, 4)
put "Quit"
Draw.Box (10, 10, 70, 40, 7)

%----------------------%
%-----MAIN PROGRAM-----%
%----------------------%

Draw.Box (90, 40, 580, 350, 7) % Canvas Area

loop
    count := 0
    loop
        count := count + 1
        Mouse.Where (x2, y2, button)
        if count = 1 then
            x := x2
            y := y2
        end if
        ColourPicker
        PencilSizePicker
        if button = 1 and x2 < 580 and x2 > 90 and y2 < 350 and y2 > 40 then
            Draw.ThickLine (x, y, x2, y2, LineThickness, LineColour)
            x := x2
            y := y2
        elsif button = 100 and x2 < 580 and x2 > 90 and y2 < 350 and y2 > 40 then
            Draw.FillBox (85, 35, 585, 355, 31)
            Draw.Box (90, 40, 580, 350, 7)
        end if
        exit when button = 0
        QuitButton
    end loop
end loop[/Code]

-----------------------------------
Raknarg
Fri Feb 22, 2013 9:50 pm

RE:My First Three Programs - details inside
-----------------------------------
Im on my iPod ATM so it's hard to look at everything. However one thing I did notice is that you split up all your operations Into four separate procedures. In fact, this can all be shortened into one, because you basically do the same thing over and over except change the operation

-----------------------------------
BigBear
Sat Feb 23, 2013 9:43 am

RE:My First Three Programs - details inside
-----------------------------------
Raknarg is right! For your first program you have a loop to get the input in each of your operation (+, -, *, /)

loop 
        get input 
        if strintok (input) then 
            y := strint (input) 
            exit 
        else 
            put "That's not a number!" 
            delay (2000) 
            clear 
            Text.Locate (4, 1) 
            put a, " + ", b, " = " .. 
        end if 
    end loop 

-----------------------------------
Cancer Sol
Thu Apr 04, 2013 7:47 pm

Re: My First Three Programs - details inside
-----------------------------------
Nice program! Way better than my brother's math program xD
His (my brother's) code... it's so hard to understand.
Not even one comment, and everything is all over the place.

Edit: You taught me how to organize my code in Turing better now :P
        I don't code in Turing anymore, but I'll have to next year in CompSci  :?
