20/04/20 18:33:21 SXRlK0qI.net
>>181 Python3 (Javaじゃなくてスマソ >>253 をインプリ, tkinterのインストールされている環境で実行ください)
import math, tkinter as tk
root = tk.Tk()
canvas = tk.Canvas(root, width=300, height=300)
canvas.pack()
x0, y0 = 150, 50
r = 200
v, theta = 0, 3.1415 * 40 / 180
x, y = x0 + r * math.sin(theta), y0 + r * math.cos(theta)
stick = canvas.create_line(x0, y0, x, y, width=2)
ball = canvas.create_oval(x-7, y-7, x+7, y+7, fill='gray')
dt = 20
def show():
global v, theta, x, y
a = -0.00098 * math.sin(theta)
a *= 0.95 if a * v > 0 else 1/0.95 # dumping
dv = a * dt;
dtheta = (v + dv/2) * dt / r
theta += dtheta;
v += dv;
x, y = x0 + r * math.sin(theta), y0 + r * math.cos(theta)
canvas.coords(stick, x0, y0, x, y)
canvas.coords(ball, x-7, y-7, x+7, y+7)
root.after(dt, show)
show()
root.mainloop()