[ Home ] [ Back ... ]

FMSLogo Code Snips


Here's a page with some interesting bits and pieces of code, typically fairly short, that I've either written or picked up somewhere (sources acknowledged where I can remember them).

Description Code
Producing lists with recursion

Here's a couple of procedures that generate a list of strings, randomly generated using ASCII codes for upper case letters. This was a reply to a mailing lisst where someone had written something similar using FOR and while LOOPS, but it seems clear that such a job may be better done using recursion - it's certainly more elegant and it's quicker.

GENLIST produces the list of 'words'. GENWORD produces the individual 'words'.

Not sure when you might want to do this though! It just illustrates a technique which can be adapted.

to genlist :l
ifelse :l=0 [op []][op (se genword (random 10)+1 genlist :l-1)]

to genword :n
ifelse :n=0 [op "][op word char (random 26)+ 65 genword :n-1]

make "wordlist genlist 5

show :wordlist


This is a bit weird. It came from a Logo mailing list where different methods of ellipse drawing were being discussed. Most were mathematical in nature involving the use of trig functions. This code however seems to use 'pure' Turtle operations to produce an ellipse.

Why does it work?

to ellipse :s :e
local "n make "n 0
repeat 360 [rt :n fd :s lt :n lt :n fd :s * :e rt :n make "n :n + 1]

ellipse 2 .5


 [ Home ] [ Back ... ]