1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > 如何使用python制作一个爱心发射器给女朋友一个惊喜!

如何使用python制作一个爱心发射器给女朋友一个惊喜!

时间:2020-09-25 06:02:17

相关推荐

如何使用python制作一个爱心发射器给女朋友一个惊喜!

很多人学习python,不知道从何学起。

很多人学习python,掌握了基本语法过后,不知道在哪里寻找案例上手。

很多已经做案例的人,却不知道如何去学习更加高深的知识。

那么针对这三类人,我给大家提供一个好的学习平台,免费领取视频教程,电子书籍,以及课程的源代码!

QQ群:883888997

先画一个爱心

源代码:

#!/usr/bin/env python# -*- coding:utf-8 -*- import turtleimport time# 画心形圆弧def hart_arc():for i in range(200):turtle.right(1)turtle.forward(2)def move_pen_position(x, y):turtle.hideturtle()# 隐藏画笔(先)turtle.up()# 提笔turtle.goto(x, y) # 移动画笔到指定起始坐标(窗口中心为0,0)turtle.down() # 下笔turtle.showturtle()# 显示画笔# 初始化turtle.setup(width=800, height=500)# 窗口(画布)大小turtle.color('red', 'pink')# 画笔颜色turtle.pensize(3) # 画笔粗细turtle.speed(1)# 描绘速度# 初始化画笔起始坐标move_pen_position(x=0,y=-180) # 移动画笔位置turtle.left(140) # 向左旋转140度turtle.begin_fill()# 标记背景填充位置# 画心形直线( 左下方 )turtle.forward(224) # 向前移动画笔,长度为224# 画爱心圆弧hart_arc()# 左侧圆弧turtle.left(120) # 调整画笔角度hart_arc()# 右侧圆弧# 画心形直线( 右下方 )turtle.forward(224)turtle.end_fill() # 标记背景填充结束位置# 点击窗口关闭程序window = turtle.Screen()window.exitonclick()

小人发射爱心源码

程序运行截图

import turtle as tfrom time import sleepdef go_to(x, y):t.up()t.goto(x, y)t.down()def head(x, y, r):go_to(x, y)t.speed(20)t.circle(r)leg(x, y)def leg(x, y):t.right(90)t.forward(180)t.right(30)t.forward(100)t.left(120)go_to(x, y - 180)t.forward(100)t.right(120)t.forward(100)t.left(120)hand(x, y)def hand(x, y):go_to(x, y - 60)t.forward(100)t.left(60)t.forward(100)go_to(x, y - 90)t.right(60)t.forward(100)t.right(60)t.forward(100)t.left(60)eye(x, y)def eye(x, y):go_to(x - 50, y + 130)t.right(90)t.forward(50)go_to(x + 40, y + 130)t.forward(50)t.left(90)def big_Circle(size):t.speed(20)for i in range(150):t.forward(size)t.right(0.3)def line(size):t.speed(20)t.forward(51 * size)def small_Circle(size):t.speed(20)for i in range(210):t.forward(size)t.right(0.786)def heart(x, y, size):go_to(x, y)t.left(150)t.begin_fill()line(size)big_Circle(size)small_Circle(size)t.left(120)small_Circle(size)big_Circle(size)line(size)t.end_fill()def main():t.pensize(2)t.color('red', 'pink')head(-120, 100, 100)heart(250, -80, 1)go_to(100, -300)t.write("To: Python代码大全", move=True, align="left", font=("楷体", 20, "normal"))t.done()main()

在这里推荐下我的Python开发学习群:883888997,群里都是学Python开发的,如果你想学或者正在学习Python ,欢迎你加入,大家都是软件开发党,不定期分享干货(只有Python软件开发相关的),包括我自己整理的一份最新的Python进阶资料和高级开发教程,欢迎进阶中和进想深入Python的小伙伴!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。