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

条件、循环、函数定义、字符串练习

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

标签:bre   字符   src   条件   分享   tle   col   钻石   练习   

1.用循环画五角星

技术分享
import turtle
turtle.setup(600,400,0,0)
turtle.color("yellow")
turtle.bgcolor(‘red‘)
turtle.fillcolor("yellow")
turtle.up()
turtle.goto(-250,75)
turtle.down()
turtle.begin_fill()
for i in range(5):
    turtle.forward(100)
    turtle.right(144)
turtle.end_fill()
技术分享

2.用循环画同心圆

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

 

3.用while循环画太阳花

技术分享
from turtle import*

color(‘red‘,‘blue‘)
begin_fill()
while True:
    forward(200)
    left(170)
    if (abs(pos()))<1:
        break
end_fill()
done()
技术分享

4.用函数定义画五个五角星

技术分享
import turtle
turtle.setup(600,400,0,0)
turtle.color("yellow")
turtle.bgcolor(‘red‘)
turtle.fillcolor("yellow")
turtle.up()
turtle.goto(-250,75)
turtle.down()
turtle.begin_fill()
for i in range(5):
    turtle.forward(100)
    turtle.right(144)
turtle.end_fill()

turtle.up()
turtle.goto(-100,-10)
turtle.down()
turtle.begin_fill()
for i in range(5):
    turtle.forward(50)
    turtle.left(144)
turtle.end_fill()

turtle.up()
turtle.goto(-50,50)
turtle.down()
turtle.begin_fill()
for i in range(5):
    turtle.forward(50)
    turtle.right(144)
turtle.end_fill()

turtle.up()
turtle.goto(-50,120)
turtle.down()
turtle.begin_fill()
for i in range(5):
    turtle.forward(50)
    turtle.right(144)
turtle.end_fill()

turtle.up()
turtle.goto(-100,160)
turtle.down()
turtle.begin_fill()
for i in range(5):
    turtle.forward(50)
    turtle.left(144)
turtle.end_fill()

turtle.color("red")
技术分享

5.用函数定义画钻石花瓣的太阳花

技术分享
import turtle

def draw_diamond(brad):
    brad.forward(100)
    brad.right(45)
    brad.forward(100)
    brad.right(135)

def draw_art():
    
    window=turtle.Screen()
    window.bgcolor("purple")
    
    brad=turtle.Turtle()
    brad.shape("turtle")
    brad.color("orange")
    brad.speed("fastest")


    for i in range(0,36):
        draw_diamond(brad)
        draw_diamond(brad)
        brad.left(10)

    brad.right(90)
    brad.forward(155)
    brad.color(‘green‘)
    brad.forward(145)

    window.exitonclick()

draw_art()

条件、循环、函数定义、字符串练习

标签:bre   字符   src   条件   分享   tle   col   钻石   练习   

原文地址:http://www.cnblogs.com/0042ljc/p/7515476.html

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