Categories: Computer

by Eric

Share

Categories: Computer

by Eric

Share

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
Télécharger “Scratch Koch snowflake” KochSnowFlake.zip – Téléchargé 3358 fois – 66,48 Ko

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


STAY IN THE LOOP

Subscribe to our free newsletter.

Leave A Comment

Related Posts

  • How to import the weekly twic[ref]TWIC: The Week in Chess[/ref] PGN[ref]PGN: Portable Game Notation[/ref] to Scid vs. PC firstly manually then by PowerShell script in Windows 10? [toc label= »Twic to Scid : table of contents »] 1. Import manually the twic PGN to Scid First of all, Mark Crowther compiles weekly chess games from the week’s […]

  • Alphabeta-based STOCKFISH becomes the new Grand Champion of the TCEC superfinal season 16 against Alpha zero-Leela chess zero compatible neural network-based Allie+Stein. The fourteen victories of STOCKFISH against AllieStein Mov C Gam ECO 14 Wins in #Mov by Stockfish 19092522 in #Gam game 034 W 026 E16l Queen’s Indian: Capablanca, Riumin, 7.Nc3 O-O; 1.d4 Nf6 […]

  • On May 28, 2019, Leela chess zero (LC0: 3589 ELO) became the Grand Champion of the Top Chess Engine Championship (TCEC) superfinal 15 against Stockfish (SF: 3587 ELO) on the score of 14 victories versus 8 in the marathon 100-game match with the time control of 120′+10″. St-Brieuc chess club provides the annotated Scid vs […]

  • Special markups « [%csl Re5] » or « [%cal Gf3e5] » in PGN comments render colored square or arrow in particular in ChessBase PGN. « [%csl Ye1,Gb1,Gc1] » or « [%cal Ga5e5, Ga5e1] » give a list of squares or arrows. Scid vs PC uses respectively « [%draw full,e5,red] » and « [%draw arrow,f3,e5,green] ». The purpose of pgnCb2Scid.ps1 is to convert the highlighted squares and colored […]