Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need to do the following. However, I am struggling with finishing the requested coding. This is from Python 3.7. Specific tasks are to: Improve

I need to do the following. However, I am struggling with finishing the requested coding. This is from Python 3.7.

Specific tasks are to:

  1. Improve the code by using the for loop.
  2. Change the Target to be a Rectangle
  3. Change the arrow to the Ball
  4. Make the ball size decreasing when it gets closer to the Target
  5. Add two lights: red and green changing colors after the ball hits the Target

from cs1graphics import * from time import sleep

scene = Canvas() scene.setBackgroundColor('skyBlue') grass = Rectangle(200, 80, Point(100,160)) grass.setFillColor('green') grass.setBorderColor('green') grass.setDepth(100) scene.add(grass) sun = Circle(20, Point(50,30)) sun.setFillColor('yellow') scene.add(sun)

target = Layer() outside = Rectangle(50, 70) outside.setFillColor('white') outside.setDepth(49) target.add(outside) middle = Rectangle(30, 50) middle.setFillColor('blue') middle.setDepth(48) target.add(middle) inside = Rectangle(20, 30) inside.setFillColor('red') inside.setDepth(47) target.add(inside) legs = Path(Point(-25,45), Point(0,0), Point(25,45)) legs.setBorderWidth(2) target.add(legs) target.move(160,110) target.setDepth(75) # in front of grass; behind arrows scene.add(target)

# prepare three arrows, but do not yet add to scene arrow1 = Circle(5) arrow1.setFillColor('purple')

arrow1.move(15,120) # initial position arrow2 = arrow1.clone() arrow3 = arrow1.clone()

dialogue = Text('Click target to fire an arrow') dialogue.move(100,170) scene.add(dialogue)

target.wait() # wait indefinitely for user event on target scene.add(arrow1) arrow1.rotate(-20) sleep(0.25) arrow1.move(41,-15) arrow1.rotate(7) sleep(0.25) arrow1.move(41,-5) arrow1.rotate(7) sleep(0.25) arrow1.move(41,5) arrow1.rotate(7) sleep(0.25) arrow1.move(41,17) arrow1.rotate(7)

target.wait() # wait indefinitely for user event on target scene.add(arrow2) arrow2.rotate(-40) sleep(0.25) arrow2.move(39,-22) arrow2.rotate(17) sleep(0.25) arrow2.move(39,-12) arrow2.rotate(17) sleep(0.25) arrow2.move(39,3) arrow2.rotate(17) sleep(0.25) arrow2.move(39,13) arrow2.rotate(17)

target.wait() # wait indefinitely for user event on target scene.add(arrow3) arrow3.rotate(-30) sleep(0.25) arrow3.move(37,-26) arrow3.rotate(10) sleep(0.25) arrow3.move(37,-11) arrow3.rotate(10) sleep(0.25) arrow3.move(37,6) arrow3.rotate(10) sleep(0.25) arrow3.move(37,21) arrow3.rotate(10) dialogue.setMessage('Good shooting!')

scene.wait() # wait for user event anywhere on canvas scene.close()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts of Database Management

Authors: Philip J. Pratt, Joseph J. Adamski

7th edition

978-1111825911, 1111825912, 978-1133684374, 1133684378, 978-111182591

More Books

Students also viewed these Databases questions

Question

Are robots going to displace all workers? Explain your answer.

Answered: 1 week ago