实验任务一
task1_1
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()
运行结果截图
task1_2
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()
运行结果截图
实验任务二
task2_1
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()
运行结果截图
task2_2
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
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) n = 10 for i in range(n): square(80) left(360/n) hideturtle() done() main()
运行结果截图
task3_2
from turtle import * speed(0) setup(800, 600) pencolor('pink') n = 10 for i in range(10): 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 = 5 # 螺旋n边形 count = 50 # 循环次数 for i in range(count): fd(size) angle += 360/n seth(angle) size += 5 hideturtle() done()
运行结果截图
实验任务五
task5_1
from turtle import * def move_to(a,b): penup() goto(a,b) pendown() def main(): move_to(-100,-100) color('black') begin_fill() for i in range(4): fd(200) left(90) end_fill() move_to(0,-100) color('red') begin_fill() left(45) fd(100*2**(1/2)) for i in range(3): left(90) fd(100*2**(1/2)) end_fill() hideturtle() done() main()
运行结果截图
task5_2
from turtle import * pensize(2) pencolor('blue') r = 40 d = 20 for i in range(5): fd(r) left(90) circle(r,90) left(90) fd(r) left(90) r += d hideturtle() done()
运行结果截图
实验任务六
绘制条状彩色颜色图谱
from turtle import * from random import random speed(0) def move_to(a,b): penup() goto(a,b) pendown() def gen_color(): return tuple((random() for i in range(3))) def main(): setup(800,600) move_to(-100,0) for i in range(20): color(gen_color()) begin_fill() for i in range(2): fd(10) left(90) fd(32) left(90) end_fill() fd(10) done() hideturtle() main()
运行结果截图
绘制一个简单的吃豆人图案
from turtle import * speed(0) def move_to(a,b): penup() goto(a,b) pendown() def p_c(a,b,c,r): move_to(a,b) color(c) begin_fill() circle(r) end_fill() bgcolor('black') color('yellow') begin_fill() move_to(100,100) left(135) circle(100,270) left(90) fd(100) right(90) fd(100) end_fill() p_c(45,75,'black',8) p_c(37,84,'white',2) hideturtle() done()
运行结果截图
标签:turtle,python,range,绘图,import,main,def,left From: https://www.cnblogs.com/wfg-www/p/17458881.html