一:
实验任务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的操作。