'=========================================================================== ' Subject: CIRCLE FUNCTIONS Date: 12-17-95 (11:37) ' Author: Mike Beckman Code: QB, QBasic, PDS ' Origin: mhscards@aol.com Packet: EGAVGA.ABC '=========================================================================== DEFINT A-Z DECLARE FUNCTION Distance! (x1, y1, x2, y2) SCREEN 12 DO CLS PRINT "You must choose at least 2 points." INPUT "How many points do you want the computer to choose randomly"; a IF a > 1 THEN EXIT DO LOOP PRINT PRINT "Do you want the computer to choose the center of the circle," PRINT "or would you like to choose it?" PRINT "(Press C for computer to choose or anything else to choose)" DO: abc$ = INKEY$: LOOP UNTIL abc$ <> "" PRINT abc$ IF INSTR("cC", abc$) THEN RANDOMIZE TIMER x = INT(RND * 640) y = INT(RND * 480) radius = INT(RND * 200) + 20 ELSE DO INPUT "X Coordinate"; x IF x >= 0 AND x <= 639 THEN EXIT DO LOOP DO INPUT "Y Coordinate"; y IF y >= 0 AND x <= 479 THEN EXIT DO LOOP DO INPUT "Radius (20 - 220)"; radius IF radius >= 20 OR radius <= 220 THEN EXIT DO LOOP END IF PRINT "Now choosing random points..." RANDOMIZE TIMER DIM x1(1 TO a) DIM y1(1 TO a) FOR ab = 1 TO a x1(ab) = INT(RND * 640) y1(ab) = INT(RND * 480) NEXT ab PRINT "Done!" PRINT PRINT "Now I'm going to draw the screen." PRINT "The circle will be blue, the center of the circle will be red, and" PRINT "all the points will be yellow." PRINT PRINT "Then I will tell you how many points are on the circle, how many" PRINT "are inside the circle, and how many are outside the circle." DO: LOOP UNTIL LEN(INKEY$) CLS FOR ab = 1 TO a PSET (x1(ab), y1(ab)), 14 NEXT ab CIRCLE (x, y), radius, 9 DO: LOOP UNTIL LEN(INKEY$) CLS inside = 0 outside = 0 oncircle = 0 timey! = TIMER FOR ab = 1 TO a dist! = Distance(x, y, x1(ab), y1(ab)) IF dist! = radius THEN oncircle = oncircle + 1 IF dist! > radius THEN outside = outside + 1 IF dist! < radius THEN inside = inside + 1 NEXT ab stoptime! = TIMER - timey! SCREEN 0 PRINT "Total Points on the screen:"; a PRINT "Total Points on the circle:"; oncircle PRINT "Total Points outside the circle:"; outside PRINT "Total Points inside the circle:"; inside PRINT "Radius of the circle:"; radius PRINT "Seconds to calculate:"; stoptime! END FUNCTION Distance! (x1, y1, x2, y2) Distance! = SQR((x2 - x1) ^ 2 + (y2 - y1) ^ 2) END FUNCTION