Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Examples > Moving Target

Moving Target

The next example is similar to the crosshairs example shown earlier in this chapter. However, unlike the earlier example that fixed the crosshairs in the middle of the screen, this example lets the user control where it is aiming by clicking the left mouse button.

from SimpleCV import Camera, Color, Display

cam = Camera()

size = cam.getImage().size()

disp = Display(size)

center = (size[0] /2, size[1] / 2)

while disp.isNotDone():
     img = cam.getImage()

     img = img.flipHorizontal()  1

     if disp.mouseLeft:
          center = (disp.mouseX, disp.mouseY)  2


     # The remainder of the example is similar to the
     # short version from earlier in the chapter

     # Inside circle
     img.dl().circle(center, 50, Color.BLACK, width = 3)
     # Outside circle
     img.dl().circle(center, 200, Color.BLACK, width = 6)

     # Radiating lines
     img.dl().line((center[0], center[1] - 50), (center[0], 0),
          Color.BLACK, width = 2)
     img.dl().line((center[0], center[1] + 50), (center[0], size[1]),
          Color.BLACK, width = 2)
     img.dl().line((center[0] - 50, center[1]), (0, center[1]),
          Color.BLACK, width = 2)
     img.dl().line((center[0] + 50, center[1]), (size[0], center[1]),
          Color.BLACK, width = 2)

     img.save(disp)

  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint