請問有沒有辦法在下面的代碼產生的影片程序中不讓圓變形?似乎除了非常慢的速度之外,影片是無法使用的扭曲。
import turtle
SPEED = 5 # ms between frames?
STEP = 5 # Pixels per "step"
def move():
global x, y, xdir, ydir
x = x xdir
y = y ydir
if x >= right_edge:
xdir = - xdir
if x <= left_edge:
xdir = - xdir
if y >= top_edge:
ydir = - ydir
if y <= bottom_edge:
ydir = -ydir
turtle.goto(x, y)
turtle.ontimer(move, SPEED)
screen = turtle.Screen()
screen.title("Bounce")
screen.bgcolor("pink")
turtle.color("blue")
turtle.shape("circle")
# turtle.shape("triangle")
turtle.penup()
x, y = 0, 0
xdir, ydir = STEP, STEP # Vectors anyone?
right_edge = turtle.window_width() // 2
left_edge = -turtle.window_width() // 2
top_edge = turtle.window_height() // 2
bottom_edge = -turtle.window_height() // 2
move()
turtle.done()
uj5u.com熱心網友回復:
我發現這dot()會產生比circle()or更高質量的圈子shape('circle'):
from turtle import Screen, Turtle, Vec2D
SPEED = 5 # ms between frames
STEP = 5 # Pixels per "step"
X, Y = 0, 1 # vector index symbols
position = Vec2D(0, 0)
direction = Vec2D(STEP, STEP) # Primitive vectors for everyone
def move():
global position, direction
position = direction
if not left_edge <= position[X] <= right_edge:
direction = Vec2D(-direction[X], direction[Y])
if not bottom_edge <= position[Y] <= top_edge:
direction = Vec2D(direction[X], -direction[Y])
turtle.clear()
turtle.goto(position)
turtle.dot(20)
screen.update()
screen.ontimer(move, SPEED)
screen = Screen()
screen.title("Bounce")
screen.bgcolor('pink')
screen.tracer(False)
turtle = Turtle()
turtle.hideturtle()
turtle.color('blue')
turtle.shape('circle')
turtle.penup()
right_edge = screen.window_width() // 2
left_edge = -screen.window_width() // 2
top_edge = screen.window_height() // 2
bottom_edge = -screen.window_height() // 2
move()
screen.mainloop()
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/506579.html
