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

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • "use strict";function _classCallCheck(e,t){if(!(e instanc...
    久些阅读 6,182评论 0 2
  • Python 是一种相当高级的语言,通过 Python 解释器把符合语法的程序代码转换成 CPU 能够执行的机器码...
    Python程序媛阅读 5,966评论 0 3
  • pyspark.sql模块 模块上下文 Spark SQL和DataFrames的重要类: pyspark.sql...
    mpro阅读 13,216评论 0 13
  • Lua 5.1 参考手册 by Roberto Ierusalimschy, Luiz Henrique de F...
    苏黎九歌阅读 14,755评论 0 38
  • 自从我重新规划了我的生活,我过得很充实,每天的时间都排的满满的,作息时间也规律多了,心情愉悦多了。 我做了喜欢的事...
    之子戚戚阅读 2,649评论 0 1

友情链接更多精彩内容