Click to display

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • OzzyB
    New Member
    • Nov 2009
    • 15

    Click to display

    Code:
    from graphics import *
    import math
    def drawCircle(win, centre, radius, colour):
        circle = Circle(centre, radius)
        circle.setFill(colour)
        circle.setWidth(2)
        circle.draw(win)
     
    def drawEye(win, centre):
        for circles in range(1):
            drawCircle(win, centre, 50, "white")
            drawCircle(win, centre, 20, "blue")
            drawCircle(win, centre, 10, "black")
    def click():    
        win=GraphWin("eye",300, 300)
        centre = Point(150,150)
        for i in range(1):
            drawCircle(win, centre , 100, "white")
            drawCircle(win, centre, 50, "yellow")
            drawCircle(win, centre, 25, "black")
            p = win.getMouse()
                iris1x=130
        iris1y=130
        iris2x=170
        iris2y=170
        pupil1x=110
        pupil2x=190
        pupil1y=110
        pupil2y=190
        sclera1x=50
        sclera2x=250
        sclera1y=50
        sclera2y=250
        clickx=p.getX()
        clicky=p.getY()
        while True:
            if clickx>=iris1x and clickx <=iris2x and clicky>=iris1y and clicky<=iris2y:
                message = Text(Point(200,280), "pupil")
                message.draw(win)
            elif clickx>=pupil1x and clickx<=pupil2x and clicky>=pupil1y and clicky<=pupil2y:
                message = Text(Point(150,280), "Iris")
                message.draw(win)
            elif clickx>=white1x and clickx<=white2x and clicky>=white1y and clicky<=white2y:
                message= Text(Point(150,280), "white")
                message.draw(win)
            else:
                win.close()
    Hello
    I am quite stuck on a python exercise and not quite sure how to finish it.
    My task is to draw an eye using a graphics module, and when the user clicks the mouse on the eye, the program is to specify what part of the eye was clicked on, so either the pupil, white or iris, and to continue this until the user clicks outside the eye to quit the window. I have sort of managed this but I can't get it to repeat. If anyone could help me get this to work and simplify it I would be greatly thankful.
  • Glenton
    Recognized Expert Contributor
    • Nov 2008
    • 391

    #2
    What does your code do when you run it at the moment?

    Comment

    Working...