(aBorder, level)
| 360 | canvas.delete('pause') |
| 361 | |
| 362 | def FillPlane(aBorder, level): |
| 363 | # a small delay allows the screen to show |
| 364 | print level, ' of ', nRecLim # when level gets too high the stack will overload |
| 365 | if level >= nRecLim - 50: |
| 366 | print 'The stack has maxed out!' |
| 367 | PauseMessage('The initial pattern is complete, press ENTER to advance.') |
| 368 | return {} |
| 369 | aBorderCopy = deepcopy(aBorder) |
| 370 | nMin = 10000 |
| 371 | k = 'all filled' |
| 372 | j = k |
| 373 | for i in aBorderCopy: |
| 374 | if i.x < nW * 0.05 or i.x > nW * 0.95: # dont go off the screen |
| 375 | continue |
| 376 | elif i.y < nH * 0.1 or i.y > nH * 0.9: |
| 377 | continue |
| 378 | elif i.priority < nMin: |
| 379 | j = i |
| 380 | nMin = i.priority |
| 381 | aAdded = [] |
| 382 | # by choosing the most sensible place to add to |
| 383 | # there is not such a need for conflict testing. |
| 384 | if j == k: # no more space to fill |
| 385 | print 'complete' |
| 386 | PauseMessage('The initial pattern is complete, press ENTER to advance.') |
| 387 | return {} |
| 388 | b = j |
| 389 | i = aBorderCopy.index(b) |
| 390 | viable = b.viable |
| 391 | shuffle(viable) |
| 392 | while len(viable) > 0: |
| 393 | v = viable[0] |
| 394 | viable = viable[1:] |
| 395 | attempt = v[0]() |
| 396 | if FitsBorder(aBorderCopy, i, v, attempt): |
| 397 | aAdded.append(attempt.tag) |
| 398 | aBorderCopy = addToBorder(aBorderCopy, i, b, v, attempt) |
| 399 | oShapesDict = FillPlane(aBorderCopy, level + 1) |
| 400 | for idtag in aAdded: |
| 401 | canvas.delete(idtag) |
| 402 | if lFinished: |
| 403 | for n in aBorder: |
| 404 | oShapesDict[n.shape.tag] = n.shape |
| 405 | return oShapesDict |
| 406 | # it might be more efficient to do some sort of clean up |
| 407 | # but this is eaisier |
| 408 | aBorderCopy = deepcopy(aBorder) |
| 409 | |
| 410 | class SubShape: |
| 411 | def draw(self): |
no test coverage detected