Simple turtle graphics

From Rosetta Code
Simple turtle graphics is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.

The first turtle graphic discussed in Mindstorms: Children, Computers, and Powerful Ideas by Seymour Papert is a simple drawing of a house. It is a square with a triangle on top for the roof.

For a slightly more advanced audience, a more practical introduction to turtle graphics might be to draw a bar chart.

See image here: https://i.imgur.com/B7YbTbZ.png

Task
  • Create a function (or subroutine) that uses turtle graphics to draw a house of a specified size as described above. Optionally make it lovely by adding details such as, for example, doors and windows.
  • Create a function (or subroutine) that takes a list (array, vector) of numbers and draws a bar chart from them, scaled to fit exactly in a square of a specified size. The enclosing square need not be drawn.
  • Both functions should return the turtle to the location it was at and facing in the same direction as it was immediately before the function was executed.

Quackery

<lang Quackery> [ $ "turtleduck.qky" loadfile ] now!

 [ behead do
   rot witheach
     [ do 2over 2over
       v< if 2swap 
       2drop ] ]                 is vmax      (       [ --> n/d )
 [ 2 times 
   [ 2dup walk
     -1 4 turn
     2over walk 
     -1 4 turn ] 
   2drop 2drop ]                 is rectangle ( n/d n/d -->     ) 
 [ 2dup rectangle ]              is square    (     n/d -->     )
 [ 3 times 
    [ 2dup walk 
      1 3 turn ] 
   2drop ]                       is triangle  (    n/d  -->     )
 [ 1 2 turn 
   2dup square triangle 
   1 2 turn ]                    is house     (     n/d -->     )
 [ stack ]                       is bar.width (         --> s   )
 [ stack ]                       is bar.scale (         --> s   )
 [ join temp put
   dup size n->v 
   temp share do v/ 1/v
   join bar.width put
   dup vmax 
   temp share do v/
   join bar.scale put    
   witheach 
     [ do 
       bar.scale share do v/
       bar.width share do
       rectangle
       bar.width share do fly ]
   temp take do -v fly
   bar.width release
   bar.scale release ]          is barchart  (   [ n/d -->     )</lang>