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

你可能感兴趣的:(python好玩的小程序)