時鐘的打印
本文免費直播課程分享鏈接:https://ke.qq.com/course/397896?flowToken=1009460
有需要學(xué)習(xí)提升的寶寶可以進去免費報名一下
每天分享一些好完的技術(shù)和主流的項目
打印時鐘:
import turtle
def draw_spiral(t, n, length=3, a=0.1, b=0.0002):
? #Draws an Archimedian spiral starting at the origin
? theta = 0.0
? for i in range(n):
? ? ? t.fd(length)
? ? ? dtheta = 1 / (a + b * theta)
? ? ? t.lt(dtheta)
? ? ? theta += dtheta
#create the world and bob
bob = turtle.Turtle()
draw_spiral(bob, n=1000)
turtle.mainloop()
花的打印
打印花:
import turtle
def polyline(t, n, length, angle):
? #Draws n line segments
? for i in range(n):
? ? ? t.fd(length)
? ? ? t.lt(angle)
def arc(t, r, angle):
? #Draws an arc with given radius and angle
? arc_length = 2 * math.pi * r * abs(angle) / 360
? n = int(arc_length / 4) + 3
? step_length = arc_length / n
? step_angle = float(angle) / n
? t.lt(step_angle/2)
? polyline(t, n, step_length, step_angle)
? t.rt(step_angle/2)
def petal(t, r, angle):
? #Draws a petal using two arcs.
? for i in range(2):
? ? ? arc(t, r, angle)
? ? ? t.lt(180 - angle)
def flower(t, n, r, angle):
? #Draws a flower with n petals
? for i in range(n):
? ? ? petal(t, r, angle)
? ? ? t.lt(360.0/n)
def move(t, length):
? #Move turtle(t) forwoard (length) units without leaving a trail
? t.pu()
? t.fd(length)
? t.pd()
bob = turtle.Turtle()
#draw a sequence of three flowers
move(bob, -100)
flower(bob, 7, 60.0, 60.0)
move(bob, 100)
flower(bob, 10, 40.0, 80.0)
move(bob, 100)
flower(bob, 20, 140.0, 20.0)
bob.hideturtle()
turtle.mainloop()
歡迎各位寶寶加入小編的交流qun
點擊鏈接加入群聊【Python技術(shù)交流】:https://jq.qq.com/?_wv=1027&k=5SvRhJ9