task1
源代码
#1.1
from turtle import * def moveto(x,y): ''' 画笔移动到坐标(x,y)处 ''' penup() goto(x,y) pendown() def draw(n,size = 100): ''' 绘制边长为size的正n边形 ''' for i in range(n): fd(size) left(360/n) def main(): pensize(2) pencolor('red') moveto(-200,0) draw(3) moveto(0,0) draw(4) moveto(200,0) draw(5) hideturtle() done() main()
运行结果截图
源代码:
#1.2 # 运用circle函数,实现正多边形绘制 from turtle import * def moveto(x,y): ''' 画笔移动到坐标(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()
运行结果截图
task2
源代码
#2.1 '''以(0,0)为圆心,绘制9个同心圆''' from turtle import * def moveto(x,y): '''把画笔移动至坐标(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()
运行结果截图
源代码:
#2.2
'''以(0,0)为圆心,绘制9个彩色同心圆,色彩随机生成''' from turtle import * from random import random def moveto(x,y): '''把画笔移至坐标(x,y)处''' penup() goto(x,y) pendown() def gen_color(): '''生成一个以rgb三元组表示的颜色值并返回''' 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
源代码
#3.1
from turtle import * def square(size = 50, rgb = 'pink'): pencolor(rgb) for i in range(4): fd(size) left(90) def main(): setup(800, 600) speed(0) n = 50 for i in range(n): square(80) left(360/n) hideturtle() done() main()
运行结果截图
源代码
#3.2 from turtle import * setup(800,600) pencolor('pink') n = 10 for i in range(n+1): #绘制一片花瓣 for j in range(2): circle(80,90) left(90) right(360/n) hideturtle() done()
运行结果截图
task4
源代码
from turtle import * setup(800, 600) bgcolor('black') pencolor('white') speed(0) angle = 0 size = 2 n = 5 # 螺旋n边形 count = 50 # 循环次数 for i in range(count): fd(size) angle += 360/n seth(angle) size += 5 hideturtle() done()
运行结果截图
task5
源代码
#5.1 # 先画外围正方形 from turtle import * def moveto(x, y): penup() goto(x, y) pendown() color('black') begin_fill() moveto(-100,-100) for i in range(4): fd(200) left(90) end_fill() # 再画内三角形 color('red') begin_fill() moveto(0,-100) left(45) for i in range(4): fd(100*2**(1/2)) left(90) end_fill() hideturtle() done()
运行结果截图
源代码
#5.2 from turtle import * setup(400, 400) pencolor('blue') pensize(2) speed(0) def func(n, r): for i in range(n): fd(r) left(90) circle(r, 90) left(90) fd(r) left(90) r += 20 func(5, 40) hideturtle() done()
运行结果截图
task6
源代码
#选做2 from turtle import * screensize(100,100,'black') def moveto(x, y): penup() goto(x, y) pendown() # 画脸 color('yellow') begin_fill() left(45) fd(100) left(90) circle(100,270) left(90) fd(100) end_fill() # 画眼睛 moveto(10,65) dot(15,'black') # 画高光 moveto(8,70) dot(8,'white') hideturtle() done()
运行结果截图
标签:moveto,range,实验,import,源代码,def,left From: https://www.cnblogs.com/wybpyx/p/17473745.html