UNIT_00: Sequences

What is a sequence?
A sequence is an ordered set of individual instructions. Each instruction runs once, in the order written. The programmer controls the outcome by controlling the order..

Log in to post a comment.

// UNIT 0 – Sequence Toy
// Title: Star (Explicit Ordered Steps)
//
// PSEUDOCODE (no loops, no logic)
// 1. Move to starting position
// 2. forward 100, right 144
// 3. forward 100, right 144
// 4. forward 100, right 144
// 5. forward 100, right 144
// 6. forward 100
//
// Notes:
// • This reproduces the star shape by writing every step.
// • No loop controls the progression.
// • The walk() timeline ends after step 5.

// Turtletoy setup
Canvas.setpenopacity(1);
const turtle = new Turtle();

// Place turtle and begin drawing
turtle.penup();
turtle.goto(-50, -20);
turtle.pendown();

// walk(i) executes one ordered step per frame.
// After the 5th explicit instruction, we stop.
function walk(i) {

    if (i === 0) {
        turtle.forward(100);
        turtle.right(144);
    }

    else if (i === 1) {
        turtle.forward(100);
        turtle.right(144);
    }

    else if (i === 2) {
        turtle.forward(100);
        turtle.right(144);
    }

    else if (i === 3) {
        turtle.forward(100);
        turtle.right(144);
    }

    else if (i === 4) {
        // final stroke completes the star
        turtle.forward(100);
    }

    // Stop after the 5th segment
    return i < 4;
}