Terrapin Resources

Snowflakes

by Bill Spezeski

This project uses a fractal formula from my book “Logo: Models and Methods for Problem Solving” to create six-sided snowflakes by altering one variable in the formula.

This project illustrates

  • illustrating fractals in Logo
  • changing variables in a formula to change designs
  • using FOR command to repeat with a counter

Snowflakes.lgo

; from Chapter 8 of Models and Methods for Problem Solving
; by Bill Spezeski

TO SETUP.FRAC :NPTS :M :R :SCALE :TILT
    CS FS WINDOW
    MAKE "ANGLE :M*(360/:NPTS)
    MAKE "LSIDE :R*(SIN :ANGLE/2)
    MAKE "ADJUST (180-:ANGLE)*:TILT +  (360-:ANGLE)*(1-:TILT)
    SETH 0
    PU FD :R/2 PD
    RT 90 + :ANGLE/2 + :ADJUST
    DRAW.FRAC :NPTS :LSIDE
END

TO DRAW.FRAC :NPTS :LSIDE
    IF :LSIDE < 10 STOP
    LT :ADJUST
    REPEAT :NPTS [FD :LSIDE DRAW.FRAC :NPTS :LSIDE * :SCALE RT :ANGLE]
    RT :ADJUST
END

TO SETUP.FRACT :NPTS :M :R :SCALE :TILT :LEVEL
    CS SETBG "NAVY SETPC "WHITE FS WINDOW
    MAKE "ANGLE :M * (360/:NPTS)
    MAKE "LSIDE :R * (SIN :ANGLE /2)
    MAKE "ADJUST (180 - :ANGLE) * :TILT + (360 - :ANGLE) *(1- :TILT)
    SETH 0
    PU FD :R /2 PD
    DRAW.FRACT :NPTS :LSIDE :LEVEL
END

TO DRAW.FRACT :NPTS :LSIDE :LEVEL
    IF :LEVEL = 0 [STOP]
    LT :ADJUST
    REPEAT :NPTS [FD :LSIDE DRAW.FRACT :NPTS :LSIDE * :SCALE (:LEVEL - 1) RT :ANGLE]
    RT :ADJUST
END

HT
(FOR "I 1 21 [SETUP.FRACT 6 1 100 .5 :i/10 4 WAIT 500] 2)

Procedure DRAW.FRACT
Description Draws six-sided snowflakes
Level Beginner
Tags Fractals, Formulae