[MWForum]random numbers, filling
Daniel Ajoy
mwforum@lists.mathcats.com
Sun, 08 Feb 2004 16:44:01 -0500
On 8 Feb 2004 at 11:23, Karen Randall wrote:
> Greetings,
Hi Karen,
> Would one of you be kind enough to comment on our class conclusions
> about a couple small programming problems? Is there a more elegant
> way around them?
>
> 1. The kids want to have random number inputs to setting turtle
> coordinate locations. We've been able to do this using setx and sety
> separately, but not setpos followed by something such as [random 20
> random 20]. Is this correct? Can you help us understand why one
> works but not the other?
That is because [random 20 random 20] is a list with four items: one
word (random), one number (20), one word and one number.
show first [random 20 random 20]
random
show item 1 [random 20 random 20]
random
show item 2 [random 20 random 20]
20
show item 3 [random 20 random 20]
random
show item 4 [random 20 random 20]
20
What you need is a list of two numbers, like:
show list random 20 random 20
1 17
show list random 20 random 20
3 19
show list random 20 random 20
18 14
"random 20" is a number
"random 20" is a another number
"list" takes both numbers and makes a list with them
> 2. When trying to fill shapes, we're adding the extra commands to
> get the turtle inside the shape and off the line it drew getting
> there so the fill command works, and then sometimes there is still
> something not cooperating. Lifting the pen before moving the turtle
> inside the shape helps a little, but is there an easier way to get
> solid color shapes (via the turtle and not the graphics tools)?
Here is a general procedure to draw a filled square,
everything cooperates:
to square :side :color
setc :color
repeat 4 [fd :side rt 90]
pu rt 45 fd :side fill bk :side rt 45 pd
end
Daniel
OpenWorld Learning