python好玩的程序-花和时钟

时钟的打印
本文免费直播课程分享链接:https://ke.qq.com/course/397896?flowToken=1009460
有需要学习提升的宝宝可以进去免费报名一下
每天分享一些好完的技术和主流的项目



打印时钟:
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技术交流】:https://jq.qq.com/?_wv=1027&k=5SvRhJ9

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值