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

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 […]

  • 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 […]

  • The draw distance in the minimum number of moves in a 1/2-1/2 chess game where StockFish evaluates the position with the « +0.00 » score for the very first time. Chess engines such as StockFish vs Leela chess draw games with a rate of 80%. Sorting these draw games according to the draw distance could help the […]

  • In order that Scid vs PC generates the Scid database of TCEC 2019 superfinal 14 STOCKFISH vs Leela Chess zero, let us introduce the PGN parser in PowerShell language for Windows 10. The 5 MB of the TCEC PGN of the Superfinal 14 could be downloaded from the legacy TCEC on Chessdom: « Season 14 – […]