* This script based on 'New Stairs'Copyright 1995 Steve Israelson
* Modified by Br'fin to make the angles work better
*
* This script makes stairs based on angles
*
* Set the leftSize stair default to the angle, +ve for clockwise
*               -ve for counter clockwise.
* Set the rightSize stair default to the width of the step at its outside edge
* Set the defaults floor height to the height of the last step.

* Set this to one to produce a debug output file for the script
* Debug 1

* Im too tired to comment this code, so you figure it out.

* Use A to store half of LeftSize
* Why? We don't want to turn LeftSize all in one step, but instead half a step
* On both corners of the inside wall of the step. -Br'fin

set A LeftSize
divide A 2

If (FloorHeight < DefaultFloorHeight)
        Repeat
                add FloorHeight StairSize
                add CeilingHeight StairSize
                If (LeftSize < 0)
                        Gosub MakeCounterClockwiseStep
                Else
                        Gosub MakeClockWiseStep
                Endif
        Until (FloorHeight >= DefaultFloorHeight)
Else
        Repeat
                add FloorHeight -StairSize
                add CeilingHeight -StairSize
                If (LeftSize < 0)
                        Gosub MakeCounterClockwiseStep
                Else
                        Gosub MakeClockWiseStep
                Endif
        Until (FloorHeight <= DefaultFloorHeight)
Endif

* Note the 2 turn A's here before and after the inner edge
* Instead of one turn LeftSize -Br'fin
Subroutine MakeCounterClockwiseStep
        turn -90
        turn A
        newLine RightSize
        turn 90
        turn A

        * Move by the length of the selected line
        newLine OrigLineLength
        * save this line for our new selected line
        pushLine
        lastPoint
        makeLine
        closePoly
        * make the saved line the selected line for the next step
        popLine
EndSub

* Note the 2 turn A's here before and after the inner edge
* Instead of one turn LeftSize -Br'fin
Subroutine MakeClockWiseStep
        * make the poly backwards, and remember the corner point
        lastPoint
        turn -90
        turn A
        move RightSize
        pushPen
        turn A
        turn -90
        move OrigLineLength
        makeLine

        * go back to that saved point
        popPen
        makeLine
        pushLine

        lastPoint
        makeLine
        closePoly

        * make the saved line the selected line for the next step
        popLine
EndSub
