实验6练习-杂谈-IT技术博客
我的位置:首页 > 杂谈>实验6练习

实验6练习

时间:2021-06-14 20:52:00 浏览: 字体: 放大 缩小


一:

实验任务3:
from turtle import *
def square(size=50,rgb="orange"):
    pencolor(rgb)
    for i in range(4):
        fd(size)
        left(90)
def main():
    setup(800,600)
    speed(0)

    for i in range(10):
        square(80)
        left(36)
    done()

if __name__=="__main__":
    main()

 

实验任务4:

from turtle import *
def huaban(size=50,rgb="pink"):
    pencolor(rgb)
    for i in range(2):
        circle(size,90)
        left(90)

def main():
    setup(800,600)
    speed(0)
    for i in range(10):
        huaban()
        left(36)
    hideturtle()
    done()

if __name__=="__main__":
    main()

  

实验任务5:

from turtle import *
speed(0)
setup(800, 600)
bgcolor('black')
pencolor('white')
angle = 0
size = 2
for i in range(10):
    for j in range(5):
        angle += 72
        seth(angle)
        fd(size)
        size += 2
undo()
hideturtle()
done()

  

实验任务6:

from turtle import *
from random import random

def rect(width,heigth,rgb):
    color(rgb)
    begin_fill()
    for i in range(2):
        fd(width)
        left(90)
        fd(heigth)
        left(90)
    fd(width)
    end_fill()

def main():
    setup(800,600)
    pen()
    speed(0)
    penup()
    goto(-200,-20)
    pendown()
    for i in range(20):
        rgb=tuple(random()for i in range(3))
        rect(20,40,rgb)

    hideturtle()
    done()

if __name__=="__main__":
    main()

  

实验总结:

   自己多尝试,多画画。根据海龟的轨迹从而去理解自己代码,就可以更快更熟练掌握turtle的操作。

 

 

 

 

标签: 实验6练习实验