许文德

导航

实验6

task1

# 以(0,0)为圆心,绘制9个同心圆
from turtle import *
# 把画笔移至坐标(x,y)
def moveto(x,y):
    penup()
    goto(x,y)
    pendown()

def main():
    setup(800, 600)
    speed(0)
# 以(0,0)为圆心坐标,绘制9个同心圆
    for radius in range(20, 200, 20):
        moveto(0, -radius)
        circle(radius)
    hideturtle()
    done()
if __name__ == '__main__':
    main()

 

 task2

# 以(0,0)为圆心,绘制9个彩色的同心圆,色彩随机生成
from turtle import *
from random import random
# 把画笔移至坐标(x,y)
def moveto(x,y):
    penup()
    goto(x,y)
    pendown()
def main():
    setup(800, 600)
    speed(0)
# 以(0,0)为圆心,绘制9个彩色同心圆
for radius in range(180, 0, -20):
    moveto(0, -radius)
    rgb = tuple(random() for i in range(3)) # 随机生成rgb颜色三元组
    color(rgb)
    begin_fill()
    circle(radius)
    end_fill()
    hideturtle()
    done()
if __name__ == '__main__':
    main()

 

 

 task3

from turtle import *
# 绘制正方形
# 参数size指定边长,rgb指定画笔颜色
# 如果没有给参数,采用默认值
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(6):
        square(80)
        left(60)
    hideturtle()
    done()
if __name__ == '__main__':
    main()

 

 task4

from turtle import *
setup(800, 600)
pencolor('pink')
for i in range(4):
# 绘制一片花瓣
    for i in range(2):
        circle(80, 90)
        left(90)
        right(90)
hideturtle()
done()

 

 task5

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(4):
        fd(size)
        angle += 91
        seth(angle)
        size += 5
hideturtle()
done()

 

 任务4

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)

    hideturtle()
    done()


if __name__ == '__main__':
    main()

 

 任务5

from turtle import *
 
setup(800, 600)
pencolor('pink')
speed(0)
for i in range(10):
    for j in range(2):
        circle(80, 90)
        left(90)
 
    right(36)
 
hideturtle()
done()

 

 任务6

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

 

 

 任务7

from turtle import *
from random import random
 
def square(size = 50, rgb = 'orange'):
    pencolor(rgb)
    for i in range(2):
        fd(size)
        left(90)
        fd(size + 25)
        left(90)
 
def moveto(x = 0, y = 0):
    penup()
    goto(x, y)
    pendown()
 
def main():
    z = -500
    setup(800, 600)
    speed(0)
    for i in range(20):
        moveto(z, 0)
        z += 50
        rgb = tuple(random() for i in range(3))
        color(rgb)
        begin_fill()
        square()
        end_fill()
 
    hideturtle()
    done()
 
if __name__ == '__main__':
    main()

 

 

 

posted on 2021-06-17 22:08  许文德  阅读(42)  评论(1编辑  收藏  举报