Cracking Down a Code #1
Today, I am looking and extracting a code on TurtleStitch so I could get a better understanding of what each block does to create a certain design.
I will go in order from top to bottom and explain the blocks:
|Figure 1 (max_stepsize=40)|
- when (flag) clicked: this block is used to control the script so when you click on the green flag, the turtle will start stitching the code.
- go to x: 0 y: 0: this block is used to direct the turtle to the center of the stage.
- set __ to __: this block is used to set the chosen variable to a given value (string or number).
a) max_stepsize is the spacing between the stitches so if it was set to 10, then it would look like the above image. If I changed it to 40, it would look like Figure 1.
b) len seems to be the size of the center of the design. When I set it to 50, I realized the center got bigger and when I set it to 100, there was an even greater difference (Figure 2).
Figure 2 (len=100)
- pen down: (check my other blog post!) it is used to start the stitching process.
Figure 3 (repeat 20)
- repeat __: this block is used to create the same pattern or to loop the blocks that are held inside that block. If I reduced the number of repetitions to 20, the design would be a lot smaller and if I increased it, it would become larger. (Figure 3)
- if __ then, else __: this block is saying that if the boolean (hexagonal block) condition is true, the code inside the first space will activate and the script will go on, but if it is false, the code in the space under else will activate.
- __ > __: this block checks if the first value is greater than the second value and if it is, then the block is true, but if it isn't then it is false. In this certain code, the len should be greater than max_stepsize so the script could continue and if it isn't, the turtle would just do what is in else.
- round __: this block rounds a given number to the nearest integer.
- if __: this block is used to state that when a condition is true, the blocks held inside will run.
- __ mod __: this block states the remainder of the division when the first value is divided by the second. In this case, len is divided by max_stepsize.
- __ / __: this block states the quotient after the first number, dividend, is divided by the second number, divisor.
- __ +__: this block adds the two values together and states the sum.
- move __ steps: this block moves the sprite forward a certain number of steps.
- turn __ __ degrees: this block rotates the direction the turtle is facing.