I'm making a game like 'angry bird'.
There are two input:power and angle.
I apply those inputs to parabolic curve.
My turtle flies, making a parabolic curve. and my turtle have to hit the target,
but my turtle draws strange curve when angle is greater than 46, angle is 30, 40 etc...
I don't know where is problem....here is my code:
'''drawing back ground lines'''
for y in range(100,-101,-100):
for x in range(-375,500,125):
x coordinate: speed(in here, that is power) * cos(anlge)*time
y coordinate: speed*sin(angle)*time - (gravity speed*time**2)/2
for time in range(1,20):
# the origin fomula is for the situation that starts from (0,0). so I think
# I should compensate it, but is it right?
x=power*math.cos(angle)*time + origin_x
y=power*math.sin(angle)*time - (((time**2)*g)/2) + origin_y
if x<origin_x: # I think it has problem...
turtle.stamp() #this is for testing
if (x==target.xcor()) and (y==target.ycor()):
print("******Target is HIT!!! ******")
print("End of Game")
Below, I reduce your code to a MVCE (minimal, complete, and verifiable example) to examine the parabolic curve drawing code. The problem I found with it is the usual one of the difference between degrees and radians. The Python math library thinks in radians but provides a conversion function for degrees. The Python turtle library thinks in degress, by default, but can switch to radians using
turtle.radians(). Either way is fine but the usage has to be consistent:
from turtle import Turtle, Screen import math import random G = 9.80665 origin_x = -480 origin_y = -180 def create_turtle(): homework = Turtle(shape='turtle') homework.hideturtle() homework.penup() homework.goto(origin_x, origin_y) homework.pendown() homework.speed(0) homework.left(45) homework.showturtle() return homework def throw_turtle(turtle): angle = int(input("Enter Angle (in degrees): ")) power = int(input("Enter Power: ")) # parabola formula: # x coordinate: speed(in here, that is power) * cos(angle)*time # y coordinate: speed*sin(angle)*time - (gravity speed * time**2)/2 for time in range(1, 20): x = power * math.cos(math.radians(angle)) * time + origin_x y = power * math.sin(math.radians(angle)) * time - (((time ** 2) * G) / 2) + origin_y turtle.goto(x, y) turtle.stamp() # this is for testing window = Screen() window.setup(1000, 400) for _ in range(3): my_turtle = create_turtle() my_turtle.color(random.choice(['red', 'green', 'blue', 'purple', 'black'])) throw_turtle(my_turtle) window.exitonclick()
> python3 test.py Enter Angle (in degrees): 30 Enter Power: 120 Enter Angle (in degrees): 45 Enter Power: 90 Enter Angle (in degrees): 60 Enter Power: 90 >
Now, what more do you want it to do parabolic curve-wise?