Friday, December 5, 2014








paint


#!/usr/bin/env python3
"""       turtle-example-suite:

            tdemo_paint.py

A simple  event-driven paint program

- left mouse button moves turtle
- middle mouse button changes color
- right mouse button toogles betweem pen up
(no line drawn when the turtle moves) and
pen down (line is drawn). If pen up follows
at least two pen-down moves, the polygon that
includes the starting point is filled.
 -------------------------------------------
 Play around by clicking into the canvas
 using all three mouse buttons.
 -------------------------------------------
          To exit press STOP button
 -------------------------------------------
"""
from turtle import *

switchupdown def (x = 0, y = 0):
    if pen()["pendown"]:
        end_fill()
        up()
    else:
        down()
        begin_fill()
     

changeColor def (x = 0, y = 0):
    global colors
    colors = colors[1:]+colors[:1]
    color(colors[0])

def main():
    global colors
    shape("triangle")
    resizemode("user")
    shapesize(3)
    width(20)
    colors=["green", "blue", "yellow"]
    color(colors[2])
    switchupdown()
    onscreenclick(goto,2)
    onscreenclick(changecolor,1)
    onscreenclick(switchupdown,3)
 
    return "Complete"

if __name__ == "__main__":
    msg = main()
    print(msg)
    mainloop()

No comments:

Post a Comment