ScratchData LogoScratchData
Back to kriblo_test's profile

Example: Branching Recursion using Clones

KRkriblo_test•Created June 5, 2021
Example: Branching Recursion using Clones
10
6
59 views
View on Scratch

Instructions

Recursive algorithms can be very powerful. But one of the key shortcomings of Scratch is that you can't use local variables in custom blocks. Having only "sprite only" variables makes certain recursive algorithms difficult to pull off, but not impossible. One way to get around this issue is to use a list as a stack, so that each level of recursion can store it's own values (see link below). Another way, which works for certain applications, is to recursively create clones which does the job under the "When I start as a clone" hat block. In this example, when the green flag is clicked, a clone is created at x=0, y=0. When a clone is created, it moves a certain distance with the pen down, and then turns a random number of degrees, then creates clones of its own, and so on. See inside. You might want to try it at TW: https://turbowarp.org/540891095 All code by me (@kriblo). Example: Simple recursive custom block: https://scratch.mit.edu/projects/539966894/ Example: Koch Curve using a stack in a recursive procedure: https://scratch.mit.edu/projects/528437799/

Project Details

Project ID540891095
CreatedJune 5, 2021
Last ModifiedJune 28, 2021
SharedJune 5, 2021
Visibilityvisible
CommentsAllowed