第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

Python Zelle 圖形和 While 循環(huán)

Python Zelle 圖形和 While 循環(huán)

白衣非少年 2021-08-05 15:10:53
我正在嘗試創(chuàng)建不重疊的矩形抽認卡并將它們放置在 Zelle Graphics 中的隨機位置。xMin 和 yMin 是矩形左上角的坐標,xMax 和 yMax 是矩形右下角的坐標。我嘗試生成隨機 (xCenter,yCenter) 坐標來創(chuàng)建一個新矩形,并檢查新矩形是否與任何現(xiàn)有矩形重疊。如果重疊,則生成新的隨機點,直到不再重疊為止。我得到了檢查重疊的功能,但后來我在 while 循環(huán)中遇到了問題。我是 Python 的初學者,因此非常感謝您的幫助!from graphics import *from random import randrange *def checkLocation(xMin,xMax,yMin,yMax,xMinList,xMaxList,yMinList,yMaxList):    for x in range (xMin,xMax):        for y in range (yMin,yMax):            for i in range(len(xMinList)):                if xMinList[i] < x < xMaxList[i] and yMinList[i] < y < yMaxList[i]:                    return False     #if the new rectangle isn't overlapping, append its 4 corner into the list for future comparison:                    xMinList.append(xMin)    xMaxList.append(xMax)    yMinList.append(yMin)    yMaxList.append(yMax)    return xMinList,xMaxList,yMinList,yMaxListdef main():    win = GraphWin("Flash Card", 800,800)    xCenter, yCenter = randrange (200,600), randrange (200,600) #display the words from the text in randomly generated locations                       xMin = xCenter - 50    xMax = xCenter + 50    yMin = yCenter - 50    yMax = yCenter + 50    xMinList = [300,500,200,100,600] #I hard coded these 4 lists for the purpose of testing    xMaxList = [350,580,220,140,650]    yMinList = [100,500,300,600,400]    yMaxList = [160,540,325,680,450]    #while checkLocation is False (location overlapping), check again until it's True (not overlapping)    while not checkLocation(xMin,xMax,yMin,yMax,xMinList,xMaxList,yMinList,yMaxList):        checkLocation(xMin,xMax,yMin,yMax,xMinList,xMaxList,yMinList,yMaxList)    xMinList, xMaxList,yMinList,yMaxList =  checkLocation(xMin,xMax,yMin,yMax,xMinList,xMaxList,yMinList,yMaxList)    rect = Rectangle (Point(xMin,yMin),Point(xMax,yMax))    rect.draw(win)主要的()
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 190 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號