【python】python turtle绘制坤坤打球 | 您所在的位置:网站首页 › 打篮球的动作画画 › 【python】python turtle绘制坤坤打球 |
一、效果图:![]()
二、准备工作 (1)、导入必要的模块: 代码首先导入了需要使用的模块:requests、lxml和csv。 import requests from lxml import etree import csv如果出现模块报错 进入控制台输入:建议使用国内镜像源 pip install 模块名称 -i https://mirrors.aliyun.com/pypi/simple我大致罗列了以下几种国内镜像源: 清华大学 https://pypi.tuna.tsinghua.edu.cn/simple 阿里云 https://mirrors.aliyun.com/pypi/simple/ 豆瓣 https://pypi.douban.com/simple/ 百度云 https://mirror.baidu.com/pypi/simple/ 中科大 https://pypi.mirrors.ustc.edu.cn/simple/ 华为云 https://mirrors.huaweicloud.com/repository/pypi/simple/ 腾讯云 https://mirrors.cloud.tencent.com/pypi/simple/
三、介绍 通过 Python 的 Turtle 模块,我们可以轻松地在屏幕上绘制各种形状和动画效果。本次项目旨在利用 Turtle 模块创建一个坤坤打篮球的动画效果 四、详解代码 首先,导入了必要的库: from turtle import * from math import *这里使用了turtle库来进行图形绘制,同时使用math库来进行数学计算。 接下来是定义了两个函数ty_c和ty,用来绘制填充颜色的椭圆形和不填充颜色的椭圆形。这两个函数主要用到了cos和sin等三角函数来计算椭圆上的点的位置,以及控制画笔的移动。 1. 函数 ty_c def ty_c(x, y, sita, a, b, p, q, c): fillcolor(c) si = 2 * pi / 100 penup() goto(x + a * cos(sita), y + a * sin(sita)) pendown() t = 0 for i in range(201): if i * si + sita |
CopyRight 2018-2019 实验室设备网 版权所有 |