码迷,mamicode.com
首页 > 其他好文 > 详细

条件、循环、函数定义 练习

时间:2017-09-13 19:21:21      阅读:133      评论:0      收藏:0      [点我收藏+]

标签:raw   port   img   nbsp   ide   draw   style   imp   blog   

a.画五角星

import turtle

for i in range(5):
    turtle.forward(100)
    turtle.right(144)

技术分享

b.画同心圆

from turtle import*

for i in range(5):
    up()
    goto(0,-20*(1+i))
    down()
    circle(20*(1+i))

技术分享

c.画太阳花

from turtle import*

color(pink,yellow)
begin_fill()
while True:
    forward(200)
    right(150)
    if(abs(pos()))<1:
        break
end_fill()
hideturtle()

技术分享

d.画五个角星

import turtle

turtle.setup(600,400,0,0)
turtle.color(yellow)
turtle.bgcolor(red)
turtle.fillcolor(yellow)

def lsw_goto(x,y):
    turtle.up()
    turtle.goto(x,y)
    turtle.down()

def lsw_draw5(r):
    turtle.begin_fill()
    for i in range(5):
        turtle.forward(r)
        turtle.right(144)
    turtle.end_fill()

lsw_goto(-250,80)
lsw_draw5(100)

lsw_goto(-150,150)
lsw_draw5(50)

lsw_goto(-100,100)
lsw_draw5(50)

lsw_goto(-90,45)
lsw_draw5(50)

lsw_goto(-150,5)
lsw_draw5(50)

turtle.hideturtle()

技术分享

e.画◇花瓣的太阳花

 

import turtle

turtle.color(yellow,blue)
turtle.bgcolor(pink)

turtle.begin_fill()
for i in range(1,37):
    
    turtle.forward(200)
    turtle.right(45)
    turtle.forward(200)
    turtle.right(135)
    turtle.forward(200)
    turtle.right(45)
    turtle.forward(200)
    turtle.right(135)
    turtle.left(10)
    turtle.speed("fastest")
turtle.right(90)
turtle.forward(500)
turtle.end_fill()
turtle.hideturtle()

技术分享

条件、循环、函数定义 练习

标签:raw   port   img   nbsp   ide   draw   style   imp   blog   

原文地址:http://www.cnblogs.com/zsy-97/p/7515530.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!