标签:tps 函数定义 port code circle down draw index pen
用循环画五角星:
import turtle turtle.setup(600,400,0,0) turtle.color(‘yellow‘) turtle.bgcolor(‘red‘) turtle.fillcolor("yellow") def my_goto(x,y): turtle.up() turtle.goto(x,y) turtle.down() def draw(r): turtle.begin_fill() for i in range(5): turtle.forward(r) turtle.right(144) turtle.end_fill() my_goto(-250,75) draw(100) my_goto(-110,120) turtle.right(315) draw(50) my_goto(-70,60) turtle.right(330) draw(50) my_goto(-60,10) turtle.right(0) draw(50) my_goto(-110,-20) turtle.right(45) draw(50)
效果图:
用循环画同心圆:
代码:
import turtle turtle.color(‘black‘) for i in range(3): turtle.up() turtle.goto(0,-20*(i+1)) turtle.down() turtle.circle(20*(i+1))
效果图:
画太阳花:
while循环画:
代码:
import turtle turtle.color(‘red‘) turtle.begin_fill() while True: turtle.forward(200) turtle.left(170) if(abs(turtle.pos())) < 1: break turtle.end_fill() turtle.done()
效果图:
函数定义画:
import turtle turtle.setup(800,600,0,0) turtle.color(‘yellow‘) turtle.pencolor(‘red‘) turtle.bgcolor(‘green‘) turtle.fillcolor("yellow") turtle.begin_fill() def draw(r): for i in range(2): turtle.forward(r) turtle.right(45) turtle.forward(r) turtle.right(135) for i in range(36): draw(100) turtle.right(10) turtle.end_fill()
效果图:
字符串:
标签:tps 函数定义 port code circle down draw index pen
原文地址:http://www.cnblogs.com/ruijin-chen/p/7519818.html