任务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()
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()
任务2
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()
任务3
from turtle import* def squre(size=50,rgb='pink'): pencolor(rgb) for i in range(4): fd(size) left(90) def main(): setup(800,600) speed(0) n=9 for i in range(n): squre(80) left(360/n) hideturtle() done() main()
from turtle import* 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()
任务4
from turtle import* setup(800,600) bgcolor('black') pencolor('white') speed(0) angle=0 size=2 n=5 count=50 for i in range(count): fd(size) angle+=360/n seth(angle) size+=5 hideturtle() done()
任务5
from turtle import* goto(-100,-100) color('black','black') begin_fill() for i in range(4): fd(200) left(90) end_fill() goto(-100,0) right(90) color('red','red') begin_fill() circle(100,steps=4) end_fill() hideturtle() done()
from turtle import* r=40 pencolor('blue') pensize(2) for i in range(5): fd(r) left(90) circle(r,90) left(180) r+=20 goto(0,0) hideturtle() done()
任务6
from turtle import* from random import random setup(800,600) def gen_color(): return tuple((random()for i in range(3))) for i in range(20): fillcolor(gen_color()) begin_fill() fd(20) left(90) fd(60) left(90) fd(20) left(90) fd(60) left(90) fd(20) end_fill() hideturtle() done()
标签:turtle,python,range,绘图,90,import,def,left From: https://www.cnblogs.com/wangzhadan/p/17457947.html