以下是完全源代码:
""" turtle与pillow生成半透明效果的图形 """ import turtle from PIL import Image,ImageDraw,ImageTk def make_circle_image(diameter=200,color=(255,0,0,127)): """生成圆形图""" im = Image.new("RGBA",(diameter,diameter)) draw = ImageDraw.Draw(im) draw.ellipse((0,0,diameter ,diameter),fill=color) return im redim = make_circle_image() greenim = make_circle_image(color=(0,127,0,127)) blueim = make_circle_image(color=(0,0,127,127)) turtle.penup() screen = turtle.getscreen() screen.setup(480,360) screen.bgpic('c:/bgsnow.png') screen.title('turtle与pillow生成半透明效果的图形by李兴球') redcircle = turtle.Shape('image',ImageTk.PhotoImage(redim)) screen.register_shape('redcircle',redcircle) greencircle = turtle.Shape('image',ImageTk.PhotoImage(greenim)) screen.register_shape('greencircle',greencircle) bluecircle = turtle.Shape('image',ImageTk.PhotoImage(blueim)) screen.register_shape('bluecircle',bluecircle) turtle.fd(-50) turtle.shape('redcircle') turtle.stamp() turtle.fd(50) turtle.shape('greencircle') turtle.stamp() turtle.fd(50) turtle.shape('bluecircle') turtle.stamp() turtle.ht()
发表评论