import time
import math
import random
import turtle
from sprites import *
def rndcolor():
r = random.randint(0,255)
g = random.randint(0,255)
b = random.randint(0,255)
return r,g,b
def draw_polygon(turtle,cors):
d = math.dist(cors[0],cors[1])
turtle.penup()
turtle.goto(cors[0])
turtle.pendown()
for x,y in cors[1:]:
turtle.goto(x,y)
turtle.goto(cors[0])
turtle.penup()
周长 = d * len(cors)
return 周长
turtle.colormode(255)
screen = Screen()
screen.setup(500,500)
screen.bgcolor('black')
screen.tracer(0,0)
A = (-200,0)
B =(200,0)
pen = Sprite('blank')
pen.width(2)
pen.color('white')
pen.draw_circle(A,B)
ft = ('黑体',16,'normal')
p = Sprite('blank') # 写圆周率的
p.sety(220)
p.pencolor('yellow')
frames = []
t = Sprite('blank')
for n in range(3,101):
t.home()
t.fd(200)
t.left(90)
points = []
for i in range(n):
t.circle(200,360/n)
points.append(t.position())
t.randomcolor()
周长 = draw_polygon(t,points)
pi = 周长/400
p.clear()
p.write(f'n={n},π={pi}',align='center',font=ft)
screen.update()
frames.append(screen.save())
t.wait(2/n)
#t.clear()
for index,frame in enumerate(frames):
frame.save(f'gframes/{index}.png')
screen.mainloop()
-
- 2026 年 3 月
- 2026 年 2 月
- 2026 年 1 月
- 2025 年 12 月
- 2025 年 11 月
- 2025 年 10 月
- 2025 年 9 月
- 2025 年 6 月
- 2025 年 5 月
- 2025 年 3 月
- 2025 年 2 月
- 2025 年 1 月
- 2024 年 12 月
- 2024 年 8 月
- 2024 年 6 月
- 2024 年 5 月
- 2024 年 4 月
- 2024 年 3 月
- 2024 年 2 月
- 2023 年 11 月
- 2023 年 9 月
- 2023 年 6 月
- 2023 年 5 月
- 2023 年 4 月
- 2023 年 3 月
- 2023 年 2 月
- 2023 年 1 月
- 2022 年 12 月
- 2022 年 11 月
- 2022 年 10 月
- 2022 年 9 月
- 2022 年 8 月
- 2022 年 7 月
- 2022 年 6 月
- 2022 年 5 月
- 2022 年 4 月
- 2022 年 3 月
- 2022 年 2 月
- 2022 年 1 月
- 2021 年 12 月
- 2021 年 11 月
- 2021 年 10 月
- 2021 年 9 月
- 2021 年 8 月
- 2021 年 7 月
- 2021 年 6 月
- 2021 年 5 月
- 2021 年 4 月
- 2021 年 3 月
- 2021 年 2 月
- 2021 年 1 月
- 2020 年 12 月
- 2020 年 11 月
- 2020 年 10 月
- 2020 年 9 月
- 2020 年 8 月
- 2020 年 7 月
- 2020 年 6 月
- 2020 年 5 月
- 2020 年 4 月
- 2020 年 3 月
- 2020 年 2 月
- 2020 年 1 月
- 2019 年 12 月
- 2019 年 11 月
- 2019 年 10 月
- 2019 年 9 月
- 2019 年 8 月
- 2019 年 7 月
- 2019 年 6 月
- 2019 年 5 月
- 2019 年 4 月
- 2019 年 3 月
- 2019 年 2 月
- 2018 年 3 月
- 2018 年 1 月
- 2017 年 9 月
- 2017 年 5 月
- 2017 年 1 月
