Draw tangram

drawtangram_previewLibreLogo can export SVG animations in the upcoming LibreOffice 4.3. The attached picture is the animated GIF preview of the SVG/SMIL Wikipedia animation about tangram drawing, see the SVG animation in your browser.
Saving animated SVG pictures needs to use only the SLEEP command within the PICTURE block. If the PICTURE block ends also with a SLEEP command, the result will be a looping SVG animation, as in this example.

TO place x y
POSITION [200+x*40, 400-y*40]
END

TO line x y x2 y2
PENUP place x y
PENDOWN place x2 y2
END

TO grid x y x2 y2
REPEAT y2-y+1 [
    line x y+REPCOUNT-1 x2 y+REPCOUNT-1
]
REPEAT x2-x+1 [
    line x+REPCOUNT-1 y x+REPCOUNT-1 y2
]
END

PICTURE “drawtangram.svg” [
PENSIZE 2 HIDETURTLE
PENCAP “ROUND”
PENCOLOR “SILVER”
grid 0 0 4 4 SLEEP 1000
PENCOLOR “BLACK”
line 0 4 4 0 SLEEP 1000
line 2 4 4 2 SLEEP 1000
line 1 3 2 4 SLEEP 1000
line 0 0 3 3 SLEEP 1000
line 3 3 3 1 SLEEP 1000
FILLCOLOR “RED” line 0 0 0 4 place 2 2 FILL
FILLCOLOR “BLUE” line 0 0 4 0 place 2 2 FILL
FILLCOLOR “GREEN” line 0 4 2 4 place 1 3 FILL
FILLCOLOR “PURPLE” line 2 4 4 4 place 4 2 FILL
FILLCOLOR “LIME” line 3 1 2 2 place 3 3 FILL
FILLCOLOR “FUCHSIA” line 2 4 1 3 place 2 2 place 3 3 FILL
FILLCOLOR “YELLOW” line 3 1 3 3 place 4 2 place 4 0 FILL
SLEEP 2000
]

Note: this code shows an example to use arbitrary Cartesian coordinate system with LibreLogo: the procedure place moves the turtle to the given coordinate, mapping it to the PostScript like coordinate system of LibreOffice. Procedure line calls place two times to draw a line. With combining line with place calls it’s possible to draw the filled tangram shapes using simple Cartesian coordinates.

The tangram is a popular dissection puzzle (see the LibreLogo turtle). Chinese mathematicians Fu Traing Wang and Chuan-Chih Hsiung proofed in 1942, that there are only 13 convex polygons can be formed by the tangram. Solving them is a good play (especially with a real tangram set):
convex_tangram_shapes_black
[The solution (with an extended LibreLogo source code moving the origin of the Cartesian coordinate system to draw multiple shapes with simple Cartesian coordinates): convex tangram shapes (SVG).]

Leave a Reply

Your email address will not be published. Required fields are marked *