Problem 2 Lists of Turtles

Problem 2 Lists of Turtles

<p> Problem 2 Lists of Turtles</p><p>Problem Create a bale of turtles and enable them to move only within a display area. As the turtles move, use two disc-shaped turtles: one to track the average location of the bale and one to track one extreme of their distribution (uppermost, lowermost, leftmost, or rightmost).</p><p>Specifications 1. Create a display area with coordinates in the range of a rectangle bounded by opposite diagonal corners at (-300, -400) and (300, 400).</p><p>2. From user input, determine a number n of turtles to create.</p><p>3. Use a list comprehension to create a list of n turtles</p><p>4. With and for the bale of turtles: </p><p> a. Begin each turtle moving randomly within the display area.</p><p> b. The turtles may be colored and color other than red or green.</p><p> c. There must be a function to calculate a turtle’s next location.</p><p> d. All turtles must remain in the display area.</p><p>5. Create a red turtle and make its position match the average location of the other n turtles. </p><p> a. There must be a function to calculate and return the average location of the n turtles.</p><p> b. The red turtle must leave a pen trail</p><p>6. Create a green turtle and make its position track exactly one of the current leftmost, rightmost, uppermost or bottommost turtle in the display.</p><p> a. There must be a function to calculate and return the proper coordinate of the current, extreme-most turtle. </p><p> b. The green turtle must leave a pen trail.</p><p> c. Use the green turtle to draw a line the complete width or height of the display area at each extreme value of turtle location found for the bale. Use a horizontal line if tracking upper- or lower-most. Use a vertical line, if tracking left- or rightmost</p><p>7. Demonstrate your program. The following image shows the state after at least 100 steps using each of the 25 turtles and tracking the average location (using the red pen trail) and the position leftmost turtle in the bale (using the green pen trail and vertical bar). </p>

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    2 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us