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

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

时间:2017-09-13 23:25:17      阅读:252      评论:0      收藏:0      [点我收藏+]

标签:goto   菱形   begin   from   import   bsp   blog   nbsp   bre   

a.五角星

import turtle
turtle.color(‘yellow‘)
turtle.begin_fill()
for i in range(5):
turtle.forward(100)
turtle.right(144)
turtle.end_fill()

技术分享

b.同心圆

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

技术分享

 c.太阳花

from turtle import*
speed(40)
color(‘red‘,‘yellow‘)
begin_fill()
while True:
forward(300)
left(179)
if(abs(pos()))<1:
break
end_fill()
done()

技术分享

d.五个五角星

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 my_draw5(r):
turtle.begin_fill()
for i in range(5):
turtle.forward(r)
turtle.right(144)
turtle.end_fill()

my_goto(-360,190)

my_draw5(100)
my_goto(-155,240)
my_draw5(50)
my_goto(-90,165)
my_draw5(50)
my_goto(-75,85)
my_draw5(50)
my_goto(-120,50)
my_draw5(50)

技术分享

e.画菱形太阳花

import turtle

def draw_center(brad):
brad.forward(125)
brad.right(45)
brad.forward(100)
brad.right(135)

def draw_flower():

window=turtle.Screen()
window.bgcolor(‘blue‘)

brad=turtle.Turtle()
brad.color(‘yellow‘)
brad.speed(20)

for i in range(1,18):
draw_center(brad)
draw_center(brad)
brad.left(20)

brad.right(70)
brad.forward(325)

window.exitonclick()

draw_flower()
turtle.hideturtle()

技术分享

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

标签:goto   菱形   begin   from   import   bsp   blog   nbsp   bre   

原文地址:http://www.cnblogs.com/blackboardf/p/7515453.html

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