[MWForum]Almost: snowflake

Mikula Family mwforum@lists.mathcats.com
Wed, 16 Jul 2003 12:02:39 -0700


--------------BFABE64A3BB0567773F280CF
Content-Type: text/plain; charset=us-ascii; x-mac-type="54455854"; x-mac-creator="4D4F5353"
Content-Transfer-Encoding: 7bit

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

--------------BFABE64A3BB0567773F280CF
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
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.
<br>How I wish I had known about OWL when I was still teaching.&nbsp; Thank
you for your help.
<p>to koch_snowflake
<br>seth -90
<br>repeat 3 [rt 120 side length level ]
<br>end
<p>to side :length :level
<br>if :level = 0 [fd :length stop]
<br>side :length / 3 :level - 1 rt 60
<br>side :length / 3 :level - 1 lt 120
<br>side :length / 3 :level - 1 rt 60
<br>side :length / 3 :level - 1
<br>end
<p>to koch_snowflake_sequence
<br><u>seth 90</u>
<br><u>setc 238</u>
<br>repeat 3 [lt 120 side length :level]
<br>end
<p>to koch_snowflakes :level
<br>if :level > level [stop]
<br>koch_snowflake_sequence
<br>pu fd length + 20 pd
<br>koch_snowflakes :level + 1
<br><u>pu fd 10 pd setc 78 fill</u>
<br><u>pu fd 110 pd setc 127 fill</u>
<br><u>pu fd 110 pd setc 117 fill</u>
<br><u>pu fd 110 pd setc 107 fill</u>
<br><u>pu fd 110 pd setc 23 fill wait 5</u>
<br><u>pu seth 180 fd 50 setsh "tri pu setpos [-10 120] pd stamp wait 5</u>
<br><u>st pu seth 90 fd 200 setc 41 pd ht fill</u>
<br><u>stopall</u>
<br>end
<p>to snowflakes
<br>cg setpensize 2 pu setpos [-180 0] pd koch_snowflakes 1
<br>end
<p>Wendy Petti wrote:
<blockquote TYPE=CITE>Kate, if you send us your MW project as an attachment
and/or show us your
<br>code for drawing multiple snowflakes, it would be easier for us to
help you
<br>stop the action.
<p>But I've attached one solution and included the code below (sorry -
I
<br>didn't bother to add color to it).&nbsp; It uses the LEVEL slider to
set the
<br>number of snowflakes you want to be drawn (beginning with level 1 and
<br>ending with the level set on the slider).&nbsp; I've removed the question
marks
<br>from the LENGTH and LEVEL variables in the SIDE procedure.&nbsp; (But
remember
<br>that (for instance) LEVEL refers to the number on the slider and :LEVEL
<br>refers to the current value of the local variable :LEVEL.&nbsp; I still
think it
<br>would be clearer if they had different names, but this method illustrates
<br>that a slider a local variable can have the same name.)&nbsp; The number
on the
<br>LEVEL slider remains fixed, while the local variable :LEVEL changes
with
<br>each recursive iteration in the SIDE procedure as well as in the
<br>KOCH_SNOWFLAKES procedure.&nbsp; I've added some additional procedures.
<br>Clicking a button called "snowflakes" will activate the turtle to draw
each
<br>level of the snowflake up to the number set on the LEVEL slider.
<p>Wendy Petti
<p>to koch_snowflake
<br>seth -90
<br>repeat 3 [rt 120 side length level]
<br>end
<p>to side :length :level
<br>if :level = 0 [fd :length stop]
<br>side :length / 3 :level - 1 lt 60
<br>side :length / 3 :level - 1 rt 120
<br>side :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 :level]
<br>end
<p>to koch_snowflakes :level
<br>if :level > level [stop]
<br>koch_snowflake_sequence
<br>pu fd length + 20 pd
<br>koch_snowflakes :level + 1
<br>end
<p>to snowflakes
<br>koch_snowflakes 1
<br>end
<p>> -----Original Message-----
<br>> From: mwforum-admin@lists.mathcats.com
<br>> [<a href="mailto:mwforum-admin@lists.mathcats.com">mailto:mwforum-admin@lists.mathcats.com</a>]On
Behalf Of Mikula Family
<br>> Sent: Tuesday, July 15, 2003 5:43 PM
<br>> To: mwforum@lists.mathcats.com
<br>> Subject: [MWForum]Re:snowflake
<br>>
<br>>
<br>> It Works!!! It Works!! I made the sliders and fooled around with
<br>> it - added
<br>> color and it is wonderful. Now - how do you make it stop after a
<br>> specified
<br>> number of shapes? I had it pick up the pen and draw the next one
<br>> beside the
<br>> first. So if you want it to make only 4, how do you tell it to stop?
<br>>
<p>&nbsp; ------------------------------------------------------------------------
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Name: koch_snowflake_2.mw2
<br>&nbsp;&nbsp; koch_snowflake_2.mw2&nbsp;&nbsp;&nbsp; Type: unspecified
type (application/octet-stream)
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Encoding: base64</blockquote>
</html>

--------------BFABE64A3BB0567773F280CF--