[MWForum]Almost: snowflake

Wendy Petti mwforum@lists.mathcats.com
Wed, 16 Jul 2003 17:11:11 -0400


This is a multi-part message in MIME format.

------=_NextPart_000_0018_01C34BBD.41B3A420
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

Oh Kate, I did not realize you wanted to start with a triangle!  Sorry!  But
the solution is fun and easy.  In the "snowflakes" procedure, on the last
command, simply change KOCH_SNOWFLAKE 1 to KOCH_SNOWFLAKE 0 and then it will
draw a triangle automatically before drawing the other iterations.  :)   In
other words, now the starting level will be 0 instead of 1.  Level 0 draws a
triangle. You can see the first command in the SIDE procedure is:

if :level = 0 [fd :length stop]

And the KOCH_SNOWFLAKE procedure tells the turtle to repeat SIDE three
times.  So for level 0, we get a triangle.

We have been giving you all of this code but we haven't explained how the
recursion works.  Daniel is an expert on understanding recursion, and I just
barely hang on by my fingernails when trying to understand it and explain
it.   So maybe he or someone else can make a stab at explaining it.  But you
have done very well in adapting the code for your purposes.

By the way, putting CG at the start of your code is fine, but remember you
can also use CLEAN which erases all of your graphics without altering the
turtle's position, and you can create a button named CG or CLEAN.
(Sometime you might want to try pressing the SNOWFLAKES several times
without erasing automatically in between each trial... you never know!)

Wendy
  -----Original Message-----
  From: mwforum-admin@lists.mathcats.com
[mailto:mwforum-admin@lists.mathcats.com]On Behalf Of Mikula Family
  Sent: Wednesday, July 16, 2003 3:03 PM
  To: mwforum@lists.mathcats.com
  Subject: [MWForum]Almost: snowflake


  I added color. I really wanted the first shape to be a plain triangle but
since I don't know how to do that - here is my work around. Sort of a
triangle family tree. I am actully out of my league with you folks. I put cg
at the beginning so I can keep testing easily.
  How I wish I had known about OWL when I was still teaching.  Thank you for
your help.
  to koch_snowflake
  seth -90
  repeat 3 [rt 120 side length level ]
  end

  to side :length :level
  if :level = 0 [fd :length stop]
  side :length / 3 :level - 1 rt 60
  side :length / 3 :level - 1 lt 120
  side :length / 3 :level - 1 rt 60
  side :length / 3 :level - 1
  end

  to koch_snowflake_sequence
  seth 90
  setc 238
  repeat 3 [lt 120 side length :level]
  end

  to koch_snowflakes :level
  if :level > level [stop]
  koch_snowflake_sequence
  pu fd length + 20 pd
  koch_snowflakes :level + 1
  pu fd 10 pd setc 78 fill
  pu fd 110 pd setc 127 fill
  pu fd 110 pd setc 117 fill
  pu fd 110 pd setc 107 fill
  pu fd 110 pd setc 23 fill wait 5
  pu seth 180 fd 50 setsh "tri pu setpos [-10 120] pd stamp wait 5
  st pu seth 90 fd 200 setc 41 pd ht fill
  stopall
  end

  to snowflakes
  cg setpensize 2 pu setpos [-180 0] pd koch_snowflakes 1
  end

  Wendy Petti wrote:

    Kate, if you send us your MW project as an attachment and/or show us
your
    code for drawing multiple snowflakes, it would be easier for us to help
you
    stop the action.
    But I've attached one solution and included the code below (sorry - I
    didn't bother to add color to it).  It uses the LEVEL slider to set the
    number of snowflakes you want to be drawn (beginning with level 1 and
    ending with the level set on the slider).  I've removed the question
marks
    from the LENGTH and LEVEL variables in the SIDE procedure.  (But
remember
    that (for instance) LEVEL refers to the number on the slider and :LEVEL
    refers to the current value of the local variable :LEVEL.  I still think
it
    would be clearer if they had different names, but this method
illustrates
    that a slider a local variable can have the same name.)  The number on
the
    LEVEL slider remains fixed, while the local variable :LEVEL changes with
    each recursive iteration in the SIDE procedure as well as in the
    KOCH_SNOWFLAKES procedure.  I've added some additional procedures.
    Clicking a button called "snowflakes" will activate the turtle to draw
each
    level of the snowflake up to the number set on the LEVEL slider.

    Wendy Petti

    to koch_snowflake
    seth -90
    repeat 3 [rt 120 side length level]
    end

    to side :length :level
    if :level = 0 [fd :length stop]
    side :length / 3 :level - 1 lt 60
    side :length / 3 :level - 1 rt 120
    side :length / 3 :level - 1 lt 60
    side :length / 3 :level - 1
    end

    to koch_snowflake_sequence
    seth -90
    repeat 3 [rt 120 side length :level]
    end

    to koch_snowflakes :level
    if :level > level [stop]
    koch_snowflake_sequence
    pu fd length + 20 pd
    koch_snowflakes :level + 1
    end

    to snowflakes
    koch_snowflakes 1
    end

    > -----Original Message-----
    > From: mwforum-admin@lists.mathcats.com
    > [mailto:mwforum-admin@lists.mathcats.com]On Behalf Of Mikula Family
    > Sent: Tuesday, July 15, 2003 5:43 PM
    > To: mwforum@lists.mathcats.com
    > Subject: [MWForum]Re:snowflake
    >
    >
    > It Works!!! It Works!! I made the sliders and fooled around with
    > it - added
    > color and it is wonderful. Now - how do you make it stop after a
    > specified
    > number of shapes? I had it pick up the pen and draw the next one
    > beside the
    > first. So if you want it to make only 4, how do you tell it to stop?
    >

      ----------------------------------------------------------------------
--
                               Name: koch_snowflake_2.mw2
       koch_snowflake_2.mw2    Type: unspecified type
(application/octet-stream)
                           Encoding: base64


------=_NextPart_000_0018_01C34BBD.41B3A420
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.3314.2100" name=3DGENERATOR></HEAD>
<BODY>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D350405920-16072003>Oh =
Kate, I did not=20
realize you wanted to start with a triangle!&nbsp; Sorry!&nbsp; But the =
solution=20
is fun and easy.&nbsp; In the "snowflakes" procedure, on the last =
command,=20
simply change KOCH_SNOWFLAKE 1 to KOCH_SNOWFLAKE 0 and then it will draw =
a=20
triangle automatically before drawing the other iterations.&nbsp; =
:)&nbsp;&nbsp;=20
In other words, now the starting level&nbsp;will be 0 instead of =
1.&nbsp; Level=20
0 draws a triangle. You can see the first command in the SIDE procedure=20
is:</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D350405920-16072003></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D350405920-16072003>if =
:level =3D 0 [fd=20
:length stop]</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D350405920-16072003></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D350405920-16072003>And =
the=20
KOCH_SNOWFLAKE procedure tells the turtle to repeat SIDE three =
times.&nbsp; So=20
for level 0, we get a triangle.</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D350405920-16072003></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D350405920-16072003>We =
have been giving=20
you all of this code but we haven't explained&nbsp;how the recursion=20
works.&nbsp; Daniel is&nbsp;an expert on understanding recursion, and I =
just=20
barely hang on by my fingernails when trying to understand it and =
explain=20
it.&nbsp;&nbsp; So maybe he or someone else can make a stab at =
explaining=20
it.&nbsp; But you have done very well in adapting the code for your=20
purposes.&nbsp; </SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D350405920-16072003></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D350405920-16072003>By the =
way, putting=20
CG at the start of your code is fine, but remember you can also use =
CLEAN which=20
erases all of your graphics without altering the turtle's position, and =
you can=20
create a button named CG or CLEAN.&nbsp;&nbsp; (Sometime you might want =
to try=20
pressing the SNOWFLAKES several times without erasing automatically in =
between=20
each trial... you never know!)</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN =
class=3D350405920-16072003></SPAN></FONT><FONT=20
face=3DArial size=3D2><SPAN =
class=3D350405920-16072003></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D350405920-16072003>Wendy</SPAN></FONT></DIV>
<BLOCKQUOTE=20
style=3D"BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: =
0px; PADDING-LEFT: 5px">
  <DIV align=3Dleft class=3DOutlookMessageHeader dir=3Dltr><FONT =
face=3DTahoma=20
  size=3D2>-----Original Message-----<BR><B>From:</B>=20
  mwforum-admin@lists.mathcats.com=20
  [mailto:mwforum-admin@lists.mathcats.com]<B>On Behalf Of </B>Mikula=20
  Family<BR><B>Sent:</B> Wednesday, July 16, 2003 3:03 PM<BR><B>To:</B>=20
  mwforum@lists.mathcats.com<BR><B>Subject:</B> [MWForum]Almost:=20
  snowflake<BR><BR></DIV></FONT>I added color. I really wanted the first =
shape=20
  to be a plain triangle but since I don't know how to do that - here is =
my work=20
  around. Sort of a triangle family tree. I am actully out of my league =
with you=20
  folks. I put cg at the beginning so I can keep testing easily. <BR>How =
I wish=20
  I had known about OWL when I was still teaching.&nbsp; Thank you for =
your=20
  help.=20
  <P>to koch_snowflake <BR>seth -90 <BR>repeat 3 [rt 120 side length =
level ]=20
  <BR>end=20
  <P>to side :length :level <BR>if :level =3D 0 [fd :length stop] =
<BR>side :length=20
  / 3 :level - 1 rt 60 <BR>side :length / 3 :level - 1 lt 120 <BR>side =
:length /=20
  3 :level - 1 rt 60 <BR>side :length / 3 :level - 1 <BR>end=20
  <P>to koch_snowflake_sequence <BR><U>seth 90</U> <BR><U>setc 238</U>=20
  <BR>repeat 3 [lt 120 side length :level] <BR>end=20
  <P>to koch_snowflakes :level <BR>if :level &gt; level [stop]=20
  <BR>koch_snowflake_sequence <BR>pu fd length + 20 pd =
<BR>koch_snowflakes=20
  :level + 1 <BR><U>pu fd 10 pd setc 78 fill</U> <BR><U>pu fd 110 pd =
setc 127=20
  fill</U> <BR><U>pu fd 110 pd setc 117 fill</U> <BR><U>pu fd 110 pd =
setc 107=20
  fill</U> <BR><U>pu fd 110 pd setc 23 fill wait 5</U> <BR><U>pu seth =
180 fd 50=20
  setsh "tri pu setpos [-10 120] pd stamp wait 5</U> <BR><U>st pu seth =
90 fd 200=20
  setc 41 pd ht fill</U> <BR><U>stopall</U> <BR>end=20
  <P>to snowflakes <BR>cg setpensize 2 pu setpos [-180 0] pd =
koch_snowflakes 1=20
  <BR>end=20
  <P>Wendy Petti wrote:=20
  <BLOCKQUOTE TYPE=3D"CITE">Kate, if you send us your MW project as an=20
    attachment and/or show us your <BR>code for drawing multiple =
snowflakes, it=20
    would be easier for us to help you <BR>stop the action.=20
    <P>But I've attached one solution and included the code below (sorry =
- I=20
    <BR>didn't bother to add color to it).&nbsp; It uses the LEVEL =
slider to set=20
    the <BR>number of snowflakes you want to be drawn (beginning with =
level 1=20
    and <BR>ending with the level set on the slider).&nbsp; I've removed =
the=20
    question marks <BR>from the LENGTH and LEVEL variables in the SIDE=20
    procedure.&nbsp; (But remember <BR>that (for instance) LEVEL refers =
to the=20
    number on the slider and :LEVEL <BR>refers to the current value of =
the local=20
    variable :LEVEL.&nbsp; I still think it <BR>would be clearer if they =
had=20
    different names, but this method illustrates <BR>that a slider a =
local=20
    variable can have the same name.)&nbsp; The number on the <BR>LEVEL =
slider=20
    remains fixed, while the local variable :LEVEL changes with <BR>each =

    recursive iteration in the SIDE procedure as well as in the=20
    <BR>KOCH_SNOWFLAKES procedure.&nbsp; I've added some additional =
procedures.=20
    <BR>Clicking a button called "snowflakes" will activate the turtle =
to draw=20
    each <BR>level of the snowflake up to the number set on the LEVEL =
slider.=20
    <P>Wendy Petti=20
    <P>to koch_snowflake <BR>seth -90 <BR>repeat 3 [rt 120 side length =
level]=20
    <BR>end=20
    <P>to side :length :level <BR>if :level =3D 0 [fd :length stop] =
<BR>side=20
    :length / 3 :level - 1 lt 60 <BR>side :length / 3 :level - 1 rt 120 =
<BR>side=20
    :length / 3 :level - 1 lt 60 <BR>side :length / 3 :level - 1 <BR>end =

    <P>to koch_snowflake_sequence <BR>seth -90 <BR>repeat 3 [rt 120 side =
length=20
    :level] <BR>end=20
    <P>to koch_snowflakes :level <BR>if :level &gt; level [stop]=20
    <BR>koch_snowflake_sequence <BR>pu fd length + 20 pd =
<BR>koch_snowflakes=20
    :level + 1 <BR>end=20
    <P>to snowflakes <BR>koch_snowflakes 1 <BR>end=20
    <P>&gt; -----Original Message----- <BR>&gt; From:=20
    mwforum-admin@lists.mathcats.com <BR>&gt; [<A=20
    =
href=3D"mailto:mwforum-admin@lists.mathcats.com">mailto:mwforum-admin@lis=
ts.mathcats.com</A>]On=20
    Behalf Of Mikula Family <BR>&gt; Sent: Tuesday, July 15, 2003 5:43 =
PM=20
    <BR>&gt; To: mwforum@lists.mathcats.com <BR>&gt; Subject:=20
    [MWForum]Re:snowflake <BR>&gt; <BR>&gt; <BR>&gt; It Works!!! It =
Works!! I=20
    made the sliders and fooled around with <BR>&gt; it - added <BR>&gt; =
color=20
    and it is wonderful. Now - how do you make it stop after a <BR>&gt;=20
    specified <BR>&gt; number of shapes? I had it pick up the pen and =
draw the=20
    next one <BR>&gt; beside the <BR>&gt; first. So if you want it to =
make only=20
    4, how do you tell it to stop? <BR>&gt;=20
    <P>&nbsp;=20
    =
------------------------------------------------------------------------ =

    =
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;=20
    Name: koch_snowflake_2.mw2 <BR>&nbsp;&nbsp;=20
    koch_snowflake_2.mw2&nbsp;&nbsp;&nbsp; Type: unspecified type=20
    (application/octet-stream)=20
    =
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
    Encoding: base64</P></BLOCKQUOTE></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_0018_01C34BBD.41B3A420--