亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

替換“if 語句條件”

替換“if 語句條件”

Helenr 2023-04-11 16:00:18
def move_dot(window, center, radius, velocity):    size = (window.get_width(), window.get_height())    for index in range(0, 2):        # update center at coordinate        center[index] = center[index] + velocity[index]        # dot edge outside window?        if (center[index] <= radius) or (center[index] + radius >= size[index]):        # change direction            velocity[index] = - velocity[index]這是我上面的代碼,用于在窗口內彈跳的程序。我的問題是我只用什么來替換if (center[index] <= radius) or (center[index] + radius >= size[index]):線,以便它的中心接觸窗口邊緣而不是在其邊緣之一接觸窗口邊緣時彈跳。(我將在下面附上完整的問題,以便任何人更好地理解我正在嘗試做的事情。[如果您希望點在其中心接觸窗口邊緣時彈跳而不是在其邊緣之一接觸窗口邊緣時彈跳,應該用什么代碼替換“if 語句條件”?你只能改變條件。您不能添加或刪除任何其他代碼。]我嘗試使用代碼if (center[index] <= 0) or (center[index] + radius >= size(window(500,400))):&if (center[index] <= 0) or (center[index] + radius >= size[window]):我會得到錯誤Incorrect: It should bounce when either coordinate of the center is less than or equal to 0 or larger than or equal to the size (width or height) of the window.。有人可以指導我或幫助我嗎?謝謝
查看完整描述

1 回答

?
湖上湖

TA貢獻2003條經驗 獲得超2個贊

基本上,您希望球在球中心碰到窗邊時反彈。它目前被編碼為在球邊緣擊中時反彈。

檢查球位置時只需刪除半徑間隙:

if (center[index] <= 0) or (center[index] >= size[index]):


查看完整回答
反對 回復 2023-04-11
  • 1 回答
  • 0 關注
  • 115 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號