
-----------------------------------
blaster009
Mon May 15, 2006 7:24 pm

Useful Procedures
-----------------------------------
Haha, just felt like making a post...This is a file I usually import into my other programs.  It's got a couple of neat things in it.


% Created by Ben Cassell
% Created 2006/01/25
% Last Updated 2006/03/01
% Useful assortment of procedures

% Show all preset colours
proc colourShow
    var window : int := Window.Open ("graphics:564;500")
    var font : int := Font.New ("timesnewroman:10")
    for i : 0 .. 16
        for j : 0 .. 14
            Draw.FillBox (i * 32, j * 32, i * 32 + 32 - 1, j * 32 + 32 - 1, (i + 1) + (j * 17))
            Draw.Text (intstr (i + 1), i * 32 + 10, 485, font, 7)
            Draw.Text (intstr (j + 1), 547, j * 32 + 10, font, 7)
        end for
    end for
end colourShow

% Find a Fibonacci number at a position: Must use 0, 1, 1, userNum
proc fibFind (numBefore, numCurrent, numPosition, numStop : int)
    if numPosition ~= numStop then
        fibFind (numCurrent, numCurrent + numBefore, numPosition + 1, numStop)
    else
        put numCurrent
    end if
end fibFind

% Find the hypoteneuse of a triangle
fcn hypFind (side1, side2 : real) : real
    result sqrt (side1 ** 2 + side2 ** 2)
end hypFind

% Reverse an array of integers
proc intReverse (var list : array 0 .. * of int)
    var tempList : array 0 .. upper (list) of int
    for i : 0 .. upper (list)
        tempList (i) := list (i)
    end for
    for i : 0 .. upper (list)
        list (i) := tempList (upper (tempList) - i)
    end for
end intReverse

% Swap two integers
proc intSwap (var list : array 0 .. * of int, pos1, pos2 : int)
    var tempNum : int
    tempNum := list (pos1)
    list (pos1) := list (pos2)
    list (pos2) := tempNum
end intSwap

% Quick sort a set of integers: Must use list, lower index, upper index
proc intSort (var list : array 0 .. * of int, left, right : int)
    var pivot : int
    intSwap (list, left, (left + right) div 2)
    var small := left
    for i : left + 1 .. right
        if list (i) 