实验八

------------恢复内容开始------------

------------恢复内容开始------------

from turtle import *

def square(size=50, rgb='orange'):
    '''绘制正方形
    参数size指定边长
    参数rgb指定画笔颜色
    如果没有给参数,采用默认值
    '''
    pencolor(rgb)
    for i in range(4):
        fd(size)
        left(90)


def main():
    setup(800, 600)
    speed(0)
    n = 5
    for i in range(n):
        square(80)
        left(360/n)
    a = 5
    left(36)
    for i in range(a):
        square(80)
        left(360 / a)


    hideturtle()
    done()





if __name__ == '__main__':
    main()

from turtle import *

setup(800, 600)
pencolor('pink')
speed(0)

n = 10
for i in range(n):
    # 绘制一片花瓣
    for j in range(2):
        circle(80, 90)
        left(90)

    right(360/n)

hideturtle()
done()

from turtle import *

setup(800, 600)
bgcolor('black')
pencolor('white')
speed(0)

angle = 0
size = 2

n = 10
for i in range(n):
    for j in range(4):
        fd(size)
        angle += 72
        seth(angle)
        size += 5

hideturtle()
done()

 

from turtle import *
from random import random
setup(800,600)
speed(0)

def rect1(w=20,h=40):
    rgb=tuple(random() for i in range(3))
    color(rgb)

    for i in range(2):
        fd(w)
        left(90)
        fd(h)
        left(90)
def moveto(x,y):
    penup()
    goto(x,y)
    pendown()
def rect2(w=20,h=40):
    rgb=tuple(random() for i in range(3))
    color(rgb)

    for i in range(2):
        fd(w)
        right(90)
        fd(h)
        right(90)
x=20
y=20
for i in range(10):
    begin_fill()
    rect1()
    moveto(x,0)
    x+=20
    end_fill()
home()
right(180)
for i in range(10):
    begin_fill()
    rect2()
    moveto(-y,0)
    y+=20
    end_fill()
hideturtle()
done()

 

------------恢复内容结束------------

------------恢复内容结束------------

posted @ 2022-06-12 10:35  刘思彤、  阅读(6)  评论(1编辑  收藏  举报