How to code the Von Koch’s snowflake curve in the Scratch language?
Scratch[c] is a visual programming language by blocks for kids from 8-year-old. Scratch is developed by the MIT Media Lab’s Lifelong Kindergarten group.
The DrawFractalVonKochN procedure needs two parameters:
- the level of generation from “0” to “4”;
- le size of the side in the variable “coté” initialized with “200” pixels.
So the kids drag-and-drop blocks to build their ideas.
The above screen capture presents the Scratch visual blocks in the offline Scratch desktop. The “DrawFractalVonKochN” procedure has the number of side equal to “4” for its argument. Try progressively “0”, then “1”, then “2” And so one until “4”. Because above “4”, the time of drawing could be very long. Otherwise use the turbo mode in the desktop to optimize the drawing without the animation of the cat.
The “0” generation of the Koch’s snowflake
Test the zero generation, which is drawn immediately:
DrawFractalVonKochN 0 coté
First generation of the Koch’s snowflake
In the “1” generation, there is one peak in the center of each segment of the triangle.
Next generations of the Koch’s curve
You can increment the generation number until “4”.
The result is the Koch snowflake, a curve looking from the Armorican coast between Paimpol and Saint-Brieuc, in Brittany, NW France.
Download “Scratch Koch snowflake”KochSnowFlake.zip – Downloaded 1103 times – 66 KB
Compare visual Scratch with textual Logo
The textual code in Logo of the snowflake is shorter than the corresponding visual block in Scratch.
You can play the generation number from “0” to “4” in the call of the function DrawFractalVonKochN at the end of the second page of the .odt document in LibreOffice Writer.
The fifth generation could be time consuming.
Link with chess
The Scratch chess club compiles resources about the Scratch language and chess projects.