实验任务一
实验源码:
from turtle import * def move(x, y): penup() goto(x, y) pendown() def draw(n, size = 100): for i in range(n): fd(size) left(360/n) def main(): pensize(2) pencolor('red') move(-200,0) draw(3) move(0, 0) draw(4) move(200, 0) draw(5) hideturtle() done() main()
实验截图:
实验源码:
from turtle import * def moveto(x, y): penup() goto(x, y) pendown() def main(): pensize(2) pencolor('blue') moveto(-150, 0) circle(50) moveto(0, 0) circle(50, steps = 4) moveto(150, 0) circle(50, steps = 5) moveto(300, 0) circle(50, steps = 6) hideturtle() done() main()
实验截图:
实验任务二
实验源码:
from turtle import * def moveto(x, y): penup() goto(x, y) pendown() def main(): setup(800, 600) radius = 20 offset = 20 for i in range(9): moveto(0, -radius) circle(radius) radius += offset hideturtle() done() main()
实验截图:
实验源码:
from turtle import * from random import random def moveto(x, y): penup() goto(x, y) pendown() def gen_color(): return tuple((random() for i in range(3))) def main(): setup(800, 600) radius = 180 offset = 20 for i in range(8): moveto(0, -radius) color(gen_color()) begin_fill() circle(radius) end_fill() radius -= offset hideturtle() done() main() 复制代码
实验截图:
task3-1
程序源码:
1 from turtle import * 2 3 def square(size = 50, rgb = 'orange'): 4 '''绘制正方形 5 :para: size:int 指定边长 (如未指定参数,使用默认值) 6 :para: c: str 指定画笔颜色值 (如未指定参数,使用默认值) 7 ''' 8 9 pencolor(rgb) 10 for i in range(4): 11 fd(size) 12 left(90) 13 14 def main(): 15 setup(800, 600) 16 speed(0) 17 18 n = 10 19 for i in range(n): 20 square(80) 21 left(360/n) 22 23 hideturtle() 24 done() 25 26 main()
运行截图:
task3-2
程序源码:
1 from turtle import * 2 3 setup(800, 600) 4 pencolor('pink') 5 6 n = 10 7 for i in range(n): 8 # 绘制一片花瓣 9 for j in range(2): 10 circle(80, 90) 11 left(90) 12 13 right(360/n) 14 15 hideturtle() 16 done()
运行截图:
task4
程序源码:
1 from turtle import * 2 3 setup(800, 600) 4 bgcolor('black') 5 pencolor('white') 6 speed(0) 7 8 angle = 0 9 size = 2 10 11 n = 5 # 螺旋n边形 12 count =50 # 循环次数 13 for i in range(count): 14 fd(size) 15 angle += 360/n 16 seth(angle) 17 size += 5 18 19 hideturtle() 20 done()
运行截图:
task5-1
程序源码:
1 from turtle import * 2 3 def start(x,y): 4 penup() 5 goto(x,y) 6 pendown() 7 8 def main(c,n,l): 9 color(c) 10 begin_fill() 11 for i in range(n): 12 fd(l) 13 left(360/n) 14 end_fill() 15 16 start(-100,-100) 17 main('black',4,200) 18 19 start(-100,0) 20 right(45) 21 main('red',4,100*2**(1/2)) 22 23 hideturtle() 24 done()
运行截图:
task5-2
程序源码:
1 from turtle import * 2 color('blue') 3 r = 20 4 for i in range(5): 5 r += 20 6 forward(r) 7 left(90) 8 circle(r,90) 9 left(90) 10 forward(r) 11 left(90) 12 forward(40) 13 goto(0,0) 14 hideturtle() 15 done()
运行截图:
task6
程序源码:
1 #6 2 from turtle import * 3 bgcolor('black') 4 pencolor('yellow') 5 6 color('yellow') 7 begin_fill() 8 left(45) 9 fd(100) 10 left(90) 11 circle(100,270) 12 left(90) 13 fd(100) 14 end_fill() 15 16 penup() 17 goto(0,60) 18 pendown() 19 color('black') 20 begin_fill() 21 circle(10) 22 end_fill() 23 24 color('white') 25 begin_fill() 26 penup() 27 goto(-10,60) 28 pendown() 29 circle(2) 30 end_fill() 31 32 hideturtle() 33 done()
运行截图:
标签:Python,range,left,import,circle,main,def,实验课 From: https://www.cnblogs.com/MaYangJie/p/17474774.html