St-Brieuc chess club

St-Brieuc chess club

Chess for all in Saint-Brieuc

Computer

Saint-Brieuc chess club does .sb3 from Scratch

How to code the Von Koch’s snowflake curve in the Scratch language?

The file extension .sb does not mean Saint-Brieuc but Scratch((Scratch manuel de référence, guide vers une informatique créative)) binary in its third version((En avant vers Scratch 3.0, Académie d’Aix-Marseille, Prim à bord Eduscol)) released on January 2, 2019.

programming the second generation of Von Koch's curve with the orange cat sprite in Scratch
“2” generation of the Von Koch’s snowflake

Scratch((Download the off-line free version of Scratch Desktop Setup 1.2.1 for Windows.)) 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.

Offline programming environment for the Scratch language and Von Koch's snowflake programming
Main entry point to run the drawing of the Koch’s snowflake

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.

Von Koch's snowflake in Scratch visual language by blocks

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

"0" generation of Von Koch's curve
Zero generation is an isosceles triangle

Test the zero generation, which is drawn immediately:

DrawFractalVonKochN 0 coté

First generation of the Koch’s snowflake

First generation of Von Koch's curve with the Scratch sprite in shape of orange cat
“1” generation of Von Koch’s curve

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.

The final drawing of the Koch's curve in Scratch

Download “Scratch Koch snowflake”

KochSnowFlake.zip – Downloaded 2697 times – 66.48 KB

Compare visual Scratch with textual Logo

programming Von Koch's snowflake in Logo inside LibreOffice Writer
Fifth generation of Koch’s curve by the green turtle in Logo in LIbreOffice Writer

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.

See also

Programmer un flocon de neige en Scratch

References