Search HoldMyTwist

Browse all posts

Episode 5

One Coat of Paint Too Many

Duck attempts to go to his mark on the stage, but the giant star is in the way.

Episodes

Computing Basics

    Duck stands inside a blank digital backdrop on the aqua monitor. Robot sits outside the screen at its painting controls.
    The blank canvas sits beside an empty history stack. Robot points at its top. The stack records reversible painting actions in this fictional editor.
    Robot applies a blue background to the digital canvas. A BLUE action card becomes the first card in the history stack.
    Robot adds a stripe over the blue background. A STRIPE action card sits above BLUE in the history stack.
    Robot adds a huge star to the digital backdrop. STAR is now the top action above STRIPE and BLUE.
    Duck tries to step onto the stage mark, which the enormous star obscures. The rest of the blue backdrop and its stripe remain visible.
    Robot targets the bottom BLUE history chip. A dashed cancelled highlight marks this wrong choice. STAR remains above STRIPE and BLUE, and all three actions remain on the canvas.
    Duck points to STAR at the top of the three-chip history. Robot stops before undoing BLUE. The giant star and stripe remain on the blue canvas.
    Robot pauses at the top of the three-card stack. STAR is above STRIPE, which is above BLUE. The canvas still shows the star.
    Robot hesitates with an empty pincer above the top STAR history chip. No undo occurs; the canvas and history remain unchanged.
    Robot undoes STAR and removes its top history card. The canvas returns to its blue background with the stripe. Duck stands on the newly visible stage mark.
    The history stack has two cards. STRIPE is above BLUE. Robot points at the new top.
    Duck points at the stripe on the canvas. Robot moves toward the undo control, leaving the canvas unchanged for the moment.
    Robot pauses before undoing again. The canvas shows blue and a stripe. The stack top is STRIPE with BLUE below it.
    Robot hesitates with an empty pincer above the top STRIPE history chip. No undo occurs; the canvas and history remain unchanged.
    Robot undoes STRIPE and removes that top card. Only the blue background remains on the digital canvas. BLUE is the only history card.
    Robot checks the single BLUE card at the top of the stack. Duck studies the plain blue canvas.
    Robot undoes BLUE and removes the last card. The canvas is blank again, matching the initial state.
    Robot tips the empty history display toward Duck. There is no top card and the digital canvas remains blank.
    Robot checks for an action before using undo again. With no action in the stack, the editor makes no further change.
    Robot paints a fresh BLUE background, then adds a fresh STRIPE. New history cards appear in that order, with STRIPE on top. This is new painting, not an unexplained redo.
    Duck bows dramatically on the clear stage mark inside the finished blue-and-stripe backdrop. Robot applauds from outside the monitor.

    Episode transcript

    A digital backdrop

    Duck is standing on the white space of the aqua monitor. Robot is outside the monitor with his painting controls.

    Duck: My stage needs a backdrop!

    Robot is pointing at the top of the history stack.

    HISTORY: EMPTY. CANVAS: BLANK

    Robot: No painting actions so far

    Robot sets blue for the color of the digital canvas.

    BOTTOM [BLUE] TOP

    Duck: Blue for the sky.

    Robot draws a stripe over blue. There's a STRIPE action card on top of BLUE in the history stack.

    BOTTOM [BLUE, STRIPE] TOP

    Robot: A stripe

    The star takes the stage

    BOTTOM [BLUE, STRIPE, STAR] TOP

    Duck attempts to go to his mark on the stage, but the giant star is in the way.

    Duck: This is where I'm supposed to be.

    Robot points at the bottom (the oldest) BLUE action in the history stack.

    BLUE is oldest. STAR is newest. NO UNDO YET

    Robot stops trying to grab BLUE.

    Undo the top action

    STAR is on top of STRIPE, STRIPE is on top of BLUE. The star is visible on the canvas.

    The canvas is now blue again with the stripe. Duck is standing on the newly-exposed stage mark.

    UNDO STAR → BOTTOM [BLUE, STRIPE] TOP

    Duck: The star is gone! I've got space again!

    History stack contains two cards, the top one is STRIPE, and the bottom one is BLUE. Robot points to the new top card.

    Robot: STRIPE is top now.

    Duck points at stripe on the canvas. Robot walks towards undo button. The canvas stays the same for now.

    Duck: one more undo please.

    Back through the history

    BOTTOM [BLUE, STRIPE] TOP. NO UNDO YET

    So all you see on the digital canvas is the blue background. The only history card there is BLUE.

    UNDO STRIPE → [BLUE]

    Duck: Just blue.

    Duck looks at the blue canvas (plain).

    Robot: The last action is BLUE

    Canvas is now empty.

    UNDO BLUE → EMPTY

    Duck: We are back where we started.

    A clear stage

    HISTORY: EMPTY. CANVAS: BLANK

    Robot: Stack is empty.

    No action in stack means editor doesn't do anything more.

    Duck: So there's nothing left to undo

    NEW ACTIONS: BLUE → STRIPE. BOTTOM [BLUE, STRIPE] TOP

    Robot: Blue and stripe. We won't put a star.

    Duck does an extreme bow against the clear stage mark in the completed blue and stripe background. Robot claps from off monitor.

    Duck: That's a big enough stage for my awesome bow!

    Last in, first out (LIFO)

    A stack allows things to be put on and taken off the top. To put something on top, use push. To take off the most recently added thing, use pop. This is called last in, first out (LIFO).

    Even after undoing the star, the blue and stripe actions before that still exist. Each time you undo, it steps backwards through the actions taken.

    In this story, we have a stack of reversible things you can do with digital painting. The most recently added action is what gets removed when you do an undo. There are several possible ways that real editors might keep track of their undo stuff.

    Try a new history

    DRAW CIRCLE → DRAW SQUARE → DRAW TRIANGLE → UNDO TRIANGLE → DRAW HEART

    Answer

    The heart is the most recently recorded action. So undoing removes the heart.

    REMAINING: CIRCLE, SQUARE. UNDO SQUARE → CIRCLE. UNDO CIRCLE → EMPTY

    Stop when the stack is empty.

    Sources

    Paul E. Black, “stack”, NIST Dictionary of Algorithms and Data Structures (opens in a new tab)