Task1:basic graph
task1_1.py
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() if __name__=="__main__": setup(700,700) main()
task1_2.py
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() if __name__=="__main__": setup(1000,300) main()
Task2:Concentric Circle
task2_1.py
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() if __name__=="__main__": main()
task2_2.py
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() if __name__=="__main__": main()
task2_2plus.py
from turtle import * import task2_2 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=20 for i in range(n): begin_fill() color(task2_2.gen_color(),task2_2.gen_color()) circle(80) end_fill() left(360/n) hideturtle() done() if __name__=='__main__': main()
Task3:Petal
task3_1.py
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=20 for i in range(n): circle(80)# left(360/n) hideturtle() done() if __name__=='__main__': main()
task3_2.py
from turtle import * setup(800, 600) pencolor('pink') pensize(10) n = 6 for i in range(6): for j in range(2): circle(90, 60) left(120) right(360/n) hideturtle() done()
task3_2plus.py
from turtle import * setup(800, 600) pencolor('pink') pensize(4) n = 11 for i in range(11): for j in range(2): circle(80, 90) left(90) right(360/n) hideturtle() done()
标签:__,Six,Experience,range,import,circle,main,def From: https://www.cnblogs.com/M-H-Bi/p/17466678.html