Question
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:
- Improve the code by using the for loop.
- Change the Target to be a Rectangle
- Change the arrow to the Ball
- Make the ball size decreasing when it gets closer to the Target
- 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started