![]() |
![]() |
|
home—info—lects—labs—exams—hws
—D2L—breeze (snow day)—tutor/PIs
We will continue our work with turtles from last time. Review / Re-explore the menu JES > Turtles: What function creates the world? WHat function creates a Turtle? What info do you need to pass in to each function?
bonus thought: How many degrees did we end up turning, altogether? 360° -- the turtle rotated exactly once while drawing the figure! If you wanted to make a pentagram or a 19-sided figure instead, can you guess how much each of the individual (5 or 19) turns should be?
Note:After calling your function, leave the turtle facing the same direction as it started.
Here's a bigger task:
Make a function
(Note that the smile doesn't have to exactly line up with the eyes;
it can be a bit off, to add to the creepy factor.)
How, exactly, will you draw the bowtie-ish thing, using two triangles? You must obey the first law of programming: No Repeated Code. If you want to (say) draw some triangles, just call the function you already wrote previously -- Easy!
hint:Have the turtle start in the middle of the bowtie-thing.
Note: your next problem is easier, if you decide that
How do you have one turtle draw two things which aren't next to each other? We need to move the turtle without drawing. Remember, the turtles have a pen tied to their tail; explore the menu JES > Turtles for functions which can lift/lower the pen.
to teacher:Common bug: Sometimes in
threeSmileys , just one of them is mysteriously missing its eyes!?! This is becausepenUp andpenDown have been called from several different functions and not restored.(It's a casualty of using
void methods and side-effects: our turtle has state that we're not specifying; perhaps every method should return aTrtl structure, and unit-tests could test that all fields of the returnedTrtl were the expected result.)
home—info—lects—labs—exams—hws
—D2L—breeze (snow day)—tutor/PIs
©2014, Ian Barland, Radford University Last modified 2014.Feb.24 (Mon) |
Please mail any suggestions (incl. typos, broken links) to ibarland ![]() |
![]() |