DECLARE SUB LEGEND () begin: COMMON SHARED op1\$, OP2\$ RANDOMIZE TIMER SCREEN 0: WIDTH 80 CONST PI = 3.141593 CALL LEGEND BLK\$ = SPACE\$(80) IF op1\$ = "1" THEN REM USER-INPUT VALUES COLOR 9: PRINT : INPUT "INPUT X-VALUE OF VERTEX 1 (0 < X <320) "; U1\$ U1 = VAL(U1\$) INPUT "INPUT Y-VALUE OF VERTEX 1 (0 < X <180) "; V1\$ V1 = VAL(V1\$) COLOR 12: PRINT : INPUT "INPUT X-VALUE OF VERTEX 2 (0 < X <320) "; U2\$ U2 = VAL(U2\$) INPUT "INPUT Y-VALUE OF VERTEX 2 (0 < X <180) "; V2\$ V2 = VAL(V2\$) COLOR 14: PRINT : INPUT "INPUT X-VALUE OF VERTEX 3 (0 < X <320) "; U3\$ U3 = VAL(U3\$) INPUT "INPUT Y-VALUE OF VERTEX 3 (0 < X <180) "; V3\$ V3 = VAL(V3\$) COLOR 7 END IF IF op1\$ = "2" THEN U1 = 60 * RND(1): V1 = 50 * RND(1) + 120 U2 = 130 + 60 * RND(1): V2 = 40 * RND(1) U3 = 240 + 80 * RND(1): V3 = 70 * RND(1) + 100 END IF SCREEN 1: CLS LINE (U1, V1)-(U2, V2) LINE (U2, V2)-(U3, V3) LINE (U3, V3)-(U1, V1) REM CALCULATE SIDES AND ANGLES S12 = SQR((U2 - U1) ^ 2 + (V2 - V1) ^ 2) S23 = SQR((U2 - U3) ^ 2 + (V2 - V3) ^ 2) S31 = SQR((U1 - U3) ^ 2 + (V1 - V3) ^ 2) SS = (S12 + S23 + S31) / 2 RI = SQR((SS - S12) * (SS - S23) * (SS - S31) / SS) A12 = 2 * ATN(RI / (SS - S12)) A23 = 2 * ATN(RI / (SS - S23)) A31 = 2 * ATN(RI / (SS - S31)) REM LOCATE TRISECTION LINES IF OP2\$ = "Y" OR OP2\$ = "y" THEN LOCATE 22, 1: PRINT BLK\$: LOCATE 22, 1 PRINT "TRISECT ANGLE 1: PRESS ANY KEY ": U\$ = INPUT\$(1) END IF A = PI - A31 - (A23 / 3): X = S12 * SIN(A23 / 3) / SIN(A) X23A = U2 + (U3 - U2) * X / S23: Y23A = V2 + (V3 - V2) * X / S23 LINE (U1, V1)-(X23A, Y23A), 1 A = PI - A12 - (A23 / 3): X = S31 * SIN(A23 / 3) / SIN(A) X23B = U3 + (U2 - U3) * X / S23: Y23B = V3 + (V2 - V3) * X / S23 LINE (U1, V1)-(X23B, Y23B), 1 IF OP2\$ = "y" OR OP2\$ = "Y" THEN LOCATE 22, 1: PRINT BLK\$: LOCATE 22, 1 PRINT "TRISECT ANGLE 2: PRESS ANY KEY ": U\$ = INPUT\$(1) END IF A = PI - A12 - (A31 / 3): X = S23 * SIN(A31 / 3) / SIN(A) X31A = U3 + (U1 - U3) * X / S31: Y31A = V3 + (V1 - V3) * X / S31 LINE (U2, V2)-(X31A, Y31A), 1 A = PI - A23 - (A31 / 3): X = S12 * SIN(A31 / 3) / SIN(A) X31B = U1 + (U3 - U1) * X / S31: Y31B = V1 + (V3 - V1) * X / S31 LINE (U2, V2)-(X31B, Y31B), 1 IF OP2\$ = "y" OR OP2\$ = "Y" THEN LOCATE 22, 1: PRINT BLK\$: LOCATE 22, 1 PRINT "TRISECT ANGLE 3: PRESS ANY KEY ": U\$ = INPUT\$(1) END IF A = PI - A23 - (A12 / 3): X = S31 * SIN(A12 / 3) / SIN(A) X12A = U1 + (U2 - U1) * X / S12: Y12A = V1 + (V2 - V1) * X / S12 LINE (U3, V3)-(X12A, Y12A), 1 A = PI - A31 - (A12 / 3): X = S23 * SIN(A12 / 3) / SIN(A) X12B = U2 + (U1 - U2) * X / S12: Y12B = V2 + (V1 - V2) * X / S12 LINE (U3, V3)-(X12B, Y12B), 1 IF OP2\$ = "y" OR OP2\$ = "Y" THEN LOCATE 22, 1: PRINT BLK\$: LOCATE 22, 1 PRINT "DRAW MORLEY TRIANGLE: PRESS ANY KEY ": U\$ = INPUT\$(1) END IF REM LOCATE TRISECTION INTERSECTIONS M1 = (Y23A - V1) / (X23A - U1): B1 = V1 - M1 * U1 M2 = (Y31B - V2) / (X31B - U2): B2 = V2 - M2 * U2 X12I = -(B1 - B2) / (M1 - M2): Y12I = M1 * X12I + B1 M1 = (Y31A - V2) / (X31A - U2): B1 = V2 - M1 * U2 M2 = (Y12B - V3) / (X12B - U3): B2 = V3 - M2 * U3 X23I = -(B1 - B2) / (M1 - M2): Y23I = M1 * X23I + B1 M1 = (Y12A - V3) / (X12A - U3): B1 = V3 - M1 * U3 M2 = (Y23B - V1) / (X23B - U1): B2 = V1 - M2 * U1 X31I = -(B1 - B2) / (M1 - M2): Y31I = M1 * X31I + B1 LINE (X12I, Y12I)-(X23I, Y23I) LINE (X23I, Y23I)-(X31I, Y31I) LINE (X31I, Y31I)-(X12I, Y12I) XC = (X12I + X23I + X31I) / 3: YC = (Y12I + Y23I + Y31I) / 3 PAINT (XC, YC), 2, 3 LOCATE 22, 1: PRINT BLK\$: LOCATE 22, 1: PRINT "PRESS ANY KEY TO CONTINUE" A\$ = INPUT\$(1) SCREEN 0: WIDTH 80: CLS INPUT "DO ANOTHER - Y/N ? "; YN\$ IF YN\$ = "Y" OR YN\$ = "y" THEN GOTO begin: END SUB LEGEND REM HELP SCREEN SCREEN 0: WIDTH 80: CLS COLOR 4: PRINT " MORLEY'S TRIANGLE": PRINT COLOR 14: PRINT "IF THE ANGLES OF A TRIANGLE ARE TRISECTED, THE INTERSECTIONS OF THE" COLOR 14: PRINT "TRISECTORS ADJACENT TO EACH SIDE ARE THE VERTICES OF AN EQUILATERAL TRIANGLE," COLOR 14: PRINT "REGARDLESS OF THE SHAPE OF THE ORIGINAL TRIANGLE. THIS EQUILATERAL TRIANGLE" COLOR 14: PRINT "IS CALLED MORLEY'S TRIANGLE.": PRINT COLOR 2: PRINT "THIS PROGRAM DEMONSTRATES MORLEY'S TRIANGLE. YOU HAVE THE FOLLOWING OPTIONS:" PRINT : COLOR 3: PRINT "DO YOU WANT" COLOR 5: PRINT " 1 - INPUT YOUR OWN COORDINATE VALUES FOR THE TRIANGLE VERTICES" COLOR 6: PRINT " 2 - HAVE THE COMPUTER DRAWS A RANDOMLY-SELECTED TRIANGLE" GETKEY1: COLOR 10: LOCATE 14, 1: PRINT : INPUT "SELECT OPTION "; op1\$ 2120 IF op1\$ <> "1" AND op1\$ <> "2" THEN GOTO GETKEY1 PRINT : COLOR 11: PRINT "YOU MAY CHOOSE TO PAUSE BETWEEN EACH STAGE OF THE CONSTRUCTION" PRINT "OR COMPLETE THE ENTIRE CONSTRUCTION WITHOUT PAUSES" GETKEY2: LOCATE 19, 1: PRINT "DO YOU WANT PROMPTS FOR EACH STEP - Y/N ?" OP2\$ = INPUT\$(1) IF OP2\$ = "y" THEN OP2\$ = "Y" IF OP2\$ = "n" THEN OP2\$ = "N" IF OP2\$ <> "Y" AND OP2\$ <> "N" THEN GOTO GETKEY2 COLOR 7: CLS END SUB