//// //// EXAMPLE-LETTER.DBN //// //// Warren Sack //// February 2003 //// // // RESULTOFDIVISIONBYZERO // // This is a constant used to represent division by zero. // set ResultOfDivisionByZero 999999 // // SLOPE // // Calculate the slope of a line that runs through // the two points specified by (X1,Y1) & (X2,Y2). // number slope X1 Y1 X2 Y2 { set Result ResultOfDivisionByZero notSame? X1 X2 { set Result ( (Y1-Y2) / (X1-X2) ) } value Result } // // YINTERCEPT // // // Given a point on a line (X,Y) and the Slope of the // line, calculate where the line intersects the Y axis. // number yIntercept X Y Slope { value (Y-(Slope*X)) } // // XINTERSECTION // // Given the equations for two lines (parameterized as // their respective YIntercepts and Slopes) calculate // the X position of their intersection. // number xIntersection Slope1 YIntercept1 Slope2 YIntercept2 { set Result ResultOfDivisionByZero notSame? Slope1 Slope2 { set Result ( (YIntercept2-YIntercept1) / (Slope1-Slope2) ) } value Result } // // SQUIRT // // Goran's squirt number designed to approximate a square root function. // number squirt In { set Out (In/2) repeat I 1 6 { set Out ((Out + (In/Out))/2) // line 0 Out (I*10) Out } value Out } // // EUCLIDEANDISTANCE // // Calculate the distance between two given points (X1,Y1) & (X2,Y2) // number euclideanDistance X1 Y1 X2 Y2 { set DX (X1-X2) set DY (Y1-Y2) set squaredD ((DX*DX)+(DY*DY)) value } // // THELETTERA // // Draw a letter A to the screen given an upper lefthand position // (LeftX,UpperY) and a Width and Height for the letter // // Known bugs: with certain Width/Height ratios the horizontal // bar of the A moves too far to the right. This appears to be // due to the fact that DBN only supports integer division. // These same routines works fine in other languages; e.g., Java. // // Good example: theLetterA 20 80 60 60 // Buggy example: theLetterA 20 80 80 60 // command theLetterA LeftX UpperY Width Height { // calculate the outside top and bottom points of the A set RightX (LeftX+Width) set LowerY (UpperY-Height) set MiddleX (LeftX+(Width/2)) // set the horizontal bar of the A at 2/3 of the way down // from the top of the letter set HorizY (UpperY - ( 2 * ( Height / 3) ) ) // calculate the slope and y intercept of the line that // constitutes the lefthand side of the A set LeftA set LeftB // do the same for the righthand side of the A set RightA set RightB // set the slope to 0 and the y intercept to HorizY // for the horizontal bar of the A set HorizA 0 set HorizB HorizY // calculate where the horizontal bar intersects with // the lefthand and the righthand sides of the A set HorizX1 set HorizX2 // draw the three lines that constitute the A line HorizX1 HorizY HorizX2 HorizY line LeftX LowerY MiddleX UpperY line MiddleX UpperY RightX LowerY } // // Test theLetterA command // paper 100 pen 0 theLetterA 20 80 60 30 theLetterA 20 80 80 60