Я не могу заставить мяч перестать колебатьсяPython

Программы на Python
Ответить Пред. темаСлед. тема
Anonymous
 Я не могу заставить мяч перестать колебаться

Сообщение Anonymous »

Я пытаюсь создать базовый интерфейс симуляции шара и луча на Python с помощью TKinter, и для начала я просто хочу, чтобы мяч немного колебался, когда достигнет заданного значения, и я попытался это сделать, но он продолжает колебаться и колеблется, и я не знаю, как его остановить (после того, как он был перемещен ползунком)
Это мой код, пожалуйста, помогите :((
from tkinter import *

root = Tk()

def update_shapes(val):
# Move the oval based on the scale value
offset = int(val)
C.coords(oval, 230 + offset, 45, 270 + offset, 85)

# Start the return animation after a delay
root.after(1500, return_to_origin)`your text`

def return_to_origin():
# Animate the oval back to its original position
current_coords = C.coords(oval)
start_x = 230
end_x = current_coords[0] # Current x position
step = 1 if end_x > start_x else -1

if end_x != start_x:
end_x -= step
C.coords(oval, end_x, 45, end_x + 40, 85)
root.update()
root.after(10, return_to_origin) # Call again after a short delay
else:
H.set(0) # Reset the scale to zero
#root.after(200, oscillate_first_back) # Start the first oscillation segment after a delay
"""
def oscillate_first_back():
# First half of first oscillation - go back
for i in range(40):
C.move(oval, -1, 0)
root.update()
root.after(10)
root.after(10, oscillate_first_forward) # Proceed to next phase

def oscillate_first_forward():
# Second half of first oscillation - go forward
for i in range(80):
C.move(oval, 1, 0)
root.update()
root.after(10)
root.after(10, oscillate_second_back) # Proceed to next phase

def oscillate_second_back():
# First half of second oscillation - go back
for i in range(20):
C.move(oval, -1, 0)
root.update()
root.after(10)
root.after(10, oscillate_second_forward) # Proceed to next phase

def oscillate_second_forward():
# Second half of second oscillation - go forward
for i in range(40):
C.move(oval, 1, 0)
root.update()
root.after(10)
root.after(10, reset_position) # Proceed to final reset

def reset_position():
# Reset the oval to the original position
C.coords(oval, 230, 45, 270, 85) # Center at original position
"""
# Create a horizontal scale
H = Scale(root, from_=-150, to=150, orient=HORIZONTAL, command=update_shapes)
H.grid(row=0, column=0)

# Create a canvas
C = Canvas(root, bg="#92dadd", height=230, width=500)

# Draw shapes
oval = C.create_oval(230, 45, 270, 85, fill="white", outline="")
line = C.create_line(100, 100, 400, 100, fill="black", width=22)
rectangle = C.create_rectangle(390, 75, 420, 220, fill="black")
motor = C.create_rectangle(100, 165, 115, 100, fill="black")

C.grid(row=1, column=0)
mainloop()


Подробнее здесь: https://stackoverflow.com/questions/791 ... scillating
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение
  • Как заставить мяч вести себя как подпрыгивающий и упругий мяч?
    Anonymous » » в форуме JAVA
    0 Ответы
    14 Просмотры
    Последнее сообщение Anonymous
  • Как заставить мяч замедлиться в Python/pygame? [дубликат]
    Anonymous » » в форуме Python
    0 Ответы
    5 Просмотры
    Последнее сообщение Anonymous
  • Не могу заставить Wayland перестать отключаться
    Anonymous » » в форуме Python
    0 Ответы
    14 Просмотры
    Последнее сообщение Anonymous
  • Как мне заставить Python перестать пропускать цикл for? [дубликат]
    Anonymous » » в форуме Python
    0 Ответы
    5 Просмотры
    Последнее сообщение Anonymous
  • Есть ли вариант, который может заставить Firefox перестать подчиняться target="_blank" или эту известную ошибку можно ис
    Anonymous » » в форуме Html
    0 Ответы
    13 Просмотры
    Последнее сообщение Anonymous

Вернуться в «Python»