Skip to content

Studio 3

Studio Worksheets

  1. Studio 3 Worksheet
  2. Studio 3 In-class Worksheet
  3. Studio 3 Extra Worksheet

More fractals 🔶

vert_fractal

Refer to slide 22 for examples of what this function should do.

function vert_fractal(rune, n) {
    // YOUR SOLUTION HERE
}

// Examples
vert_fractal(heart, 1);
vert_fractal(heart, 5);
Answers

This is approach is similar to the fractal function seen in the Rune Reading mission! Instead of going left to right, here we are doing it bottom up.

function vert_fractal {
    return n === 1 
            ? rune 
            : stack(vert_fractal(n-1, beside(rune, rune)), rune);
}

corner_fractal

Refer to slide 23 for examples of what this function should do.

function corner_fractal(rune, n) {
    // YOUR SOLUTION HERE
}

// Examples
corner_fractal(heart, 1);
corner_fractal(heart, 5);
Answers

Notice how we can reuse both the fractal and vert_fractal functions to create this new function!

function corner_fractal {
    return n === 1 
             ? rune
             : beside(vert_fractal(n, rune),
                      stack(corner_fractal(n - 1, rune), 
                            fractal(n - 1, stack(rune, rune))));
}

Wishful Thinking ✨ and Recursion 🔁

  1. https://blog.thesoftwarecraft.com/2013/11/wishful-programming.html
  2. https://www.youtube.com/embed/ngCos392W4w