1 / 8

The Wait-Until-Event pattern Has it happened  Has it happened  Has it happened 

The Wait-Until-Event pattern Has it happened  Has it happened  Has it happened  Has it happened  Yes, it happened!. The Definite Loop pattern. for k in range(...): ... . window = zg.GraphWin ( 'Animation' , 650 , 430 ) x = 20 y = 5 0 radius = 5

kamali
Download Presentation

The Wait-Until-Event pattern Has it happened  Has it happened  Has it happened 

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. The Wait-Until-Event pattern Has it happened Has it happened Has it happened Has it happened Yes, it happened!

  2. The Definite Loop pattern for k in range(...): ... ... window = zg.GraphWin('Animation', 650, 430) x = 20 y = 50 radius = 5 fork inrange(150): circle = zg.Circle(zg.Point(x, y), radius) circle.setFill('purple') circle.draw(window) x = x + 2 y = y + 1 radius = radius + k / 100 time.sleep(0.01) Determines how many times the loop iterates The body of the loop

  3. The Definite Loop pattern for k in range(...): ... ... window = zg.GraphWin('Animation', 650, 430) x = 20 y = 50 radius = 5 fork inrange(150): circle = zg.Circle(zg.Point(x, y), radius) circle.setFill('purple') circle.draw(window) x = x + 2 y = y + 1 radius = radius + k / 100 time.sleep(0.01)

  4. The Definite Loop pattern The Wait-Until-Event pattern Repeatedly: ... Has the event occurred? If so, break out of the loop. ... Run n times: ... ...

  5. The Wait-Until-Event pattern Repeatedly: ... Has the event of interest occurred? If so, break out of the loop. ... Robot: Start moving. Repeatedly: Robot: Have you bumped into anything? If so, break out of the loop. Robot: Stop. Repeatedly: x = something input from the user if x is the “sentinel” value: break out of the loop Processx. 463 814 22 -1

  6. The Wait-Until-Event pattern Expressed in Python using while True and break while True: ... if the event of interest occurred: break ... robot.go(..., 0) while True: sensor = 'BUMPS_AND_WHEEL_DROPS' bump = robot.getSensor(sensor) if bump[3] == 1 or bump[4] == 1: break robot.stop() while True: msg = 'Enter int, or -1 to stop' x = int(input(msg)) if x == -1: break Processx.

  7. for k in range(...): ... ... The Definite Looppattern Do the following 150 times: Draw a circle. Move and grow the circle. while True: ... if the event of interest occurred: break ... TheWait-Until-Event pattern • Repeatedly draw, move and grow a circle, stopping when the circle grows beyond the border of the window. • Do blah until the user asks you to stop. • Robot, go until you hit a wall. • Robot, go until your sensors say that you have gone 10 centimeters.

  8. The Wait-Until-Event pattern while True: ... if the event of interest occurred: break ... • Repeatedly draw, move and grow a circle, stopping when the circle grows beyond the border of the window. • Do blah until the user asks you to stop. • Robot, go until you hit a wall. • Robot, go until your sensors say that you have gone 10 centimeters.

More Related