
-----------------------------------
fishtastic
Sun Dec 30, 2007 2:32 pm

Turing Paint
-----------------------------------
After getting bored of playing flash games for 7 days in a row.
I decided share more stuff out of the turing games I made last year.

This is a drawing program done in turing.
copy and paste into turing to use it.

it comes with a help and you wont miss it , so... ya
Have fun with it and happy new year  :dance:  :dance: 

var version := "1.2"
var loadtime := 0.0
var mx, my, mc : int
var selected := 255
var chosen := 1
var key : array char of boolean
var actions : flexible array 1 .. 0 of int
var ax1, ax2, ay1, ay2 : flexible array 1 .. 0 of int
var step : flexible array 1 .. 0 of int
var aColor : flexible array 1 .. 0 of int
var thick : flexible array 1 .. 0 of int
var toolName : array 0 .. 9 of string := init ("erasor", "Line", "brush", "rectangle", "oval", "star", "mapleleaf", "fillshape", "fillblank", "no")
var thickness := 1.0
var tool := 1
var name := ""
View.Set ("offscreenonly")

%var pass : string
%get pass
%assert pass = "thisisforjohn"
proc help
    var ch : char
    cls
    color (red)
    put "Welcome to Turing Paint " + version
    put "Press 'h' at ANY TIME for HELP"
    put ""
    color (black)
    put "select colour at the bottom of the window"
    put "press '0'~'9' to select tools"
    put "press '+' and '-' to adjust line thickness"
    put "press 'z' to move 1 step back"
    put "press 's' to save and 'l' to load"
    put "press 'w' and 'q' to selection previous and next colour"
    put ""
    put "press any key to continue"
    View.Update
    ch := getchar
end help

proc newAll
    new actions, upper (actions) + 1
    new ax1, upper (ax1) + 1
    new ay1, upper (ay1) + 1
    new ax2, upper (ax2) + 1
    new ay2, upper (ay2) + 1
    new aColor, upper (aColor) + 1
    new thick, upper (thick) + 1

    actions (upper (actions)) := 0
    aColor (upper (aColor)) := 0
    ax1 (upper (ax1)) := 0
    ay1 (upper (ay1)) := 0
    ax2 (upper (ax1)) := 0
    ay2 (upper (ay1)) := 0
    thick (upper (thick)) := 0
end newAll
%
proc back
    if upper (actions) > 0 then
        loop
            exit when upper (actions) = step (upper (step))
            new actions, upper (actions) - 1
            new ax1, upper (ax1) - 1
            new ay1, upper (ay1) - 1
            new ax2, upper (ax2) - 1
            new ay2, upper (ay2) - 1
            new aColor, upper (aColor) - 1
            new thick, upper (thick) - 1
        end loop
        new step, upper (step) - 1
        delay (50)
    end if
end back
%
proc drawAll
    for i : 1 .. upper (actions)
        if actions (i) = 0 then
            Draw.ThickLine (ax1 (i), ay1 (i), ax2 (i), ay2 (i), thick (i), white)
        elsif actions (i) = 1 then
            Draw.ThickLine (ax1 (i), ay1 (i), ax2 (i), ay2 (i), thick (i), aColor (i))
        elsif actions (i) = 2 then
            Draw.ThickLine (ax1 (i), ay1 (i), ax2 (i), ay2 (i), thick (i), aColor (i))
        elsif actions (i) = 3 then
            drawfillbox (ax1 (i), ay1 (i), ax2 (i), ay2 (i), aColor (i))
        elsif actions (i) = 4 then
            drawfilloval (ax1 (i), ay1 (i), ax2 (i) - ax1 (i), ay2 (i) - ay1 (i), aColor (i))
        elsif actions (i) = 5 then
            drawfillstar (ax1 (i), ay1 (i), ax2 (i), ay2 (i), aColor (i))
        elsif actions (i) = 6 then
            drawfillmapleleaf (ax1 (i), ay1 (i), ax2 (i), ay2 (i), aColor (i))
        elsif actions (i) = 7 then
            drawfill (ax1 (i), ay1 (i), aColor (i), 0)
        elsif actions (i) = 8 then
            drawfill (ax1 (i), ay1 (i), 255, aColor (i))
        end if
    end for
end drawAll
%
proc showStat
    if (Time.Elapsed - loadtime not= 0) then
        color (black)
        put "FPS:", 1000 / (Time.Elapsed - loadtime) : 4 : 0, "  Total Points:", upper (ay2)
        color (red)
        put toolName (tool), " tool"
        put "thickness: ", round (thickness), "  colour #: ", chosen
    end if
end showStat

proc showAll
    for i : 0 .. maxcolor
        drawfillbox (round ((maxx / maxcolor) * i), 0, round ((maxx / maxcolor) * i) + 3, 20, i)
    end for
    drawfillbox (0, 20, maxx, 40, chosen)
    if my < 20 then
        drawfillbox (0, 20, maxx, 40, selected)
    end if
    loadtime := Time.Elapsed
end showAll

%
proc save (name : string)
    var OUT : int
    open : OUT, name, put
    for i : 1 .. upper (ax1)
        put : OUT, ax1 (i)
        put : OUT, ay1 (i)
        put : OUT, ax2 (i)
        put : OUT, ay2 (i)
        put : OUT, actions (i)
        put : OUT, thick (i)
        put : OUT, aColor (i)
    end for
    put "saved!!"
    delay (1000)
    close : OUT
end save
%
proc load (name : string)
    for i : 1 .. upper (ax1) + 1
        back
    end for
    var IN : int
    open : IN, name, get
    newAll
    loop
        get : IN, ax1 (upper (ax1))
        get : IN, ay1 (upper (ay1))
        get : IN, ax2 (upper (ax2))
        get : IN, ay2 (upper (ay2))
        get : IN, actions (upper (actions))
        get : IN, thick (upper (thick))
        get : IN, aColor (upper (aColor))
        exit when eof (IN) = true
        newAll
    end loop
    put "loaded!!"
    delay (1000)
    close : IN
end load
%
proc checkKeys
    Input.KeyDown (key)
    if key (chr (ord ("+"))) then
        thickness += 0.2
    elsif key (chr (ord ("-"))) and thickness > 1 then
        thickness -= 0.2
    elsif key (chr (ord ("z"))) then
        back
        put "canceled 1 move"
        View.Update
        delay (100)
    elsif key (chr (ord ("h"))) then
        help
    elsif key (chr (ord ("s"))) then
        cls
        View.Set ("nooffscreenonly")
        put "File name(type 'cancel' to cancel)"
        get name
        if name not= "cancel" then
            save (name + ".txt")
        end if
        View.Set ("offscreenonly")
    elsif key (chr (ord ("l"))) then
        cls
        View.Set ("nooffscreenonly")
        put "File name(type 'cancel' to cancel)"
        get name
        if name not= "cancel" then
            load (name + ".txt")
        end if
        View.Set ("offscreenonly")
    elsif key (chr (ord ("q"))) then
        if chosen > 0 then
            chosen -= 1
        end if
    elsif key (chr (ord ("w"))) then
        if chosen < 255 then
            chosen += 1
        end if
    end if
    for i : 0 .. 9
        if key (chr (ord (intstr (i)))) then
            tool := i
        end if
    end for
end checkKeys
% real codes
help

loop
    cls
    mousewhere (mx, my, mc)
    showStat
    drawAll
    showAll
    checkKeys
    %
    if mc = 1 and my > 20 then
        new step, upper (step) + 1
        step (upper (step)) := upper (ax1)
        newAll
        actions (upper (actions)) := tool
        aColor (upper (aColor)) := chosen
        ax1 (upper (ax1)) := mx
        ay1 (upper (ay1)) := my
        thick (upper (thick)) := round (thickness)
        loop

            cls
            mousewhere (mx, my, mc)

            ax2 (upper (ax2)) := mx
            ay2 (upper (ay2)) := my

            showStat
            drawAll
            showAll

            exit when mc = 0
            if tool = 0 or tool = 2
                    then
                newAll
                actions (upper (actions)) := tool
                aColor (upper (aColor)) := chosen
                ax1 (upper (ax1)) := mx
                ay1 (upper (ay1)) := my
                thick (upper (thick)) := round (thickness)
            end if
            View.Update
            delay (10)
        end loop
    elsif my < 20 and round (mx / (maxx / maxcolor)) > -1 and round (mx / (maxx / maxcolor)) 