Lab 09: Trees & Fractals

Due at: Thursday, February 26th, 23:59

Lab 9: Trees & Fractals

Instructions

This worksheet serves as a guide and set of instructions to complete the lab.

  • You must use the starter file, found here to get credit for the lab.
  • Additionally, here is the workbook that you can read through for further context and additional (non-required) material. All material was sourced from the CS10 version of The Beauty and Joy of Computing course.

Submitting

You will need to fill in the blocks under the starter file and submit this to Gradescope.

  • To receive full credit for the coding portion, you will need to complete the required blocks, and the required blocks must pass all tests from the autograder in Gradescope.
  • For instructions on how to submit to labs to Gradescope, please see this page.

Please note: you must use the starter file above, and you must NOT edit the name of any of the required blocks. Failing to do either will result in autograder failure.

Objectives

Today you will continue to build your knowledge of recursion and understand how we can use recursion to move across data structures (trees, linked lists). We will start by navigating through visual fractals. By the end of lab you will:

  • Explore the idea of representing a problem in terms of itself.
  • Practice planning and coding recursive blocks.
  • Create your own fractals

Required Blocks

** It is highly recommended that you work with a partner for this assignment.

  • DO NOT CHANGE THE COLOR OF YOUR PEN
  • Block 1: snowflake segment levels: (level) size: (size)
    • You can use only recursion. No HOFs or iteration allowed.
  • Block 2: complete snowflake segment levels: (level) size: (size)
    • You must use Block 1 in your solution
    • Recursion is not used for this question
  • Block 3: c-curve segment levels: (level) size: (size)
    • You can use only recursion. No HOFs or iteration allowed.

Important Topics mentioned in the Workbook

For better understanding of the lab we highly recommend going through these workbook pages! Topics that are important but not required for this lab will be indicated with an asterisk**. These topics are best reviewed in order and as you complete the lab.


Block 1: snowflake segment levels: (level) size: (size)

  • Objective:
    • Build a function that can create on side of a coch’s snowflalke
    • example of one side of a koch's snowflake
  • Notes:
    • You must use recursion, no HOFs or iteration
    • Each recursive call is one-third the size of the caller
    • **Tip for fractals: The sprite must end in the correct direction (angle!!) at the end
    • example of a level three snowflake segment
  • Inputs:
    • Level = any number
      • Should be a positive number that indicates the level (2-5 shown below)
      • examples of level 2-5 snowflake segments
      • Size = any number
        • Should be any positive number indicates the length of an entire snowflake segment
  • Output:
    • None! It is a procedure / non-pure function, so it only displays a visual effect on the stage and does not output any values
      • We are working on a command block!
  • Examples:
    • example call to snowflake segment with level 5 and size 200
    • example output from call to snowflake segment with level 5 and size 200

Block 2: complete snowflake segment levels: (level) size: (size)

  • Objective:
    • Build a function that will create a koch snowflake. The entire snowflake consists of three copies of the previous fractal, arranged in a triangular shape.
  • Notes:
    • You must use the previous block, snowflake segment levels: (level) size: (size), in your solution
    • Recursion is not used for this question
  • Inputs:
    • Level = any number
      • Should be a positive number that indicates the level
    • Size = any number
      • Should be any positive number indicates the length of an entire snowflake segment
  • Output:
    • None! It is a procedure / non-pure function, so it only displays a visual effect on the stage and does not output any values
  • Examples:
    • example of output of complete snowflake segment levels

Block 3: c-curve levels: (level) size: (size)

  • Objective:
    • Build a function that will create a fractal called a c-curve. The fractal should recurse a c-curve shape to create a complex fractal. Please look at this workbook page for more instructions.
    • example output of c-curve levels
  • Notes:
    • You must use recursion. No HOFs.
    • Each recursive call is one-half the size of the caller
    • example call to c-curve with level 2
  • Inputs:
    • Level = any number
      • Should be a positive number that indicates the level
    • Size = any number
      • Should be any positive number indicates the total length of the fractal
  • Output:
    • None! It is a procedure / non-pure function, so it only displays a visual effect on the stage and does not output any values
  • Examples:
    • example of output of c-curve levels
    • THE COLOR IS TO SHOW THE DIFFERENT PARTS OF THE C-CURVE.

You can always check the validity of your solutions by using the local autograder. Remember to submit on Gradescope!

Submission

You may submit more than once before the deadline; only the final submission will be graded. It is your responsibility to check that the autograder on Gradescope runs as expected after you upload your submission.