'============================================================================ ' G.H. George EPICYC.BAS 2001 08 17 ' Traces epicycloids of n cusps from a circle with 120 points. ' From SYMmetry plus, #15, Summer 2001 (Mathematical Association), p. 10. '============================================================================ ' Procedures: ' Intro() prints introductory screen ' x(i) returns the x coordinate of point i on the circle ' y(i) returns the y coordinate of point i on the circle DECLARE SUB Intro () DECLARE FUNCTION x# (i AS INTEGER) DECLARE FUNCTION y# (i AS INTEGER) ' Global constants: ' Pi: pi ' numPoints: number of points on the circle DEFINT N CONST Pi = 3.141592653589794# CONST numPoints = 120 ' Variables: ' n number of cusps on the epicycloid ' i loop counter = index number of point ' j index number of point (n+1) times further along the circle DIM n AS INTEGER, i AS INTEGER, j AS INTEGER CALL Intro SCREEN 8 FOR n = 1 TO 5 IF n = 1 THEN PRINT "Epicycloid of 1 cusp (cardioid)" ELSE PRINT "Epicycloid of"; n; "cusps" END IF '--------------------------------------------------------------------------- ' Set the radius of the guide circle r = 90 pixels on the ' 640x200 SCREEN 8 and its centre at (xc, yc) = (320, 100) pixels. ' Each point is at (xi, yi), where ' xi = xc + r*cos(theta) ' yi = yc + r*sin(theta) [evaluated in functions x(i), y(i)] ' angle theta = (i/numPoints)*360 deg ' The other end of the line is at (xj, yj), (n+1) times further along ' the guide circle, at angle (n+1)*theta, which is equivalent to ' i -> (n+1)*i MOD numPoints '--------------------------------------------------------------------------- FOR i = 1 TO numPoints j = ((n + 1) * i) MOD numPoints LINE (x(i), y(i))-(x(j), y(j)), 14 ' Yellow lines NEXT i DO WHILE INKEY$ = "": LOOP ' Pause until key pressed. IF n < 5 THEN CLS NEXT n END SUB Intro '============================================================================ ' Print introductory screen. '============================================================================ ' No procedures or local variables. SCREEN 0: CLS : COLOR 11, 0 ' Cyan on black PRINT TAB(25); "Program Epicyc.bas" PRINT TAB(25); " ==========" PRINT PRINT "From each of"; numPoints; "points on a guide circle, "; PRINT "a line is drawn" PRINT "to the point (n+1) times further along the guide circle." PRINT "The envelope formed by all of these lines is an epicycloid of"; PRINT " n cusps." PRINT "This is a crude implementation of the algorithm presented by" PRINT "David Crawford in the article "; PRINT CHR$(34); "Curves from Straight Lines"; CHR$(34); ", in" PRINT "SYMmetry plus, #15, Summer 2001 (Mathematical Association), page 10." PRINT PRINT "In order to proceed from one value of n to the next, "; PRINT "press any key." PRINT COLOR 14, 0 ' Yellow on black PRINT "Press any key to continue: "; DO WHILE INKEY$ = "": LOOP ' Pause until any key is pressed. END SUB DEFDBL X FUNCTION x (i AS INTEGER) '============================================================================ ' Returns the x coordinate of point i on the circle '============================================================================ ' No procedures or local variables. ' angle theta = (i/numPoints)*360 deg ' xi = xc + r*cos(theta) x = 320 + 90 * COS((i / numPoints) * 2 * Pi) * 12 / 5 ' Aspect ratio correction: 10/5 for screenshot, 12/5 for monitor. END FUNCTION DEFDBL Y FUNCTION y (i AS INTEGER) '============================================================================ ' Returns the y coordinate of point i on the circle '============================================================================ ' No procedures or local variables. ' angle theta = (i/numPoints)*360 deg ' yi = yc + r*sin(theta) y = 100 + 90 * SIN((i / numPoints) * 2 * Pi) END FUNCTION