《python程序语言设计》2018版第5章第52题利用turtle绘制sin函数


这道题是送分题。因为循环方式已经写到很清楚,大家照抄就可以了。

但是如果说光照抄可是会有问题。比如我们来演示一下。

python 复制代码
import turtle

turtle.penup()
turtle.goto(-175, 50 * math.sin((-175 / 100 * 2 * math.pi)))
turtle.pendown()
for x in range(-175, 176):
    turtle.goto(x, 50 * math.sin((x / 100 * 2 * math.pi)))

turtle.hideturtle
turtle.done()

这个问题我慢慢的思考明白。今天这个其实不是很难。

这句话即代表了起点也是整个线段的绘制。

python 复制代码
 turtle.goto(x, 50 * math.sin((x / 100 * 2 * math.pi)))

我是不是应该先把turle放到sin这个线断起始点再开始绘制呢?

所以我在循环外又加写了一句

python 复制代码
import turtle

turtle.speed(40)
turtle.penup()
turtle.goto(-175, 50 * math.sin((-175 / 100 * 2 * math.pi)))
turtle.pendown()
for x in range(-175, 176):
    turtle.goto(x, 50 * math.sin((x / 100 * 2 * math.pi)))

turtle.hideturtle
turtle.done()

##结果成功了

接下来丰富一下其他内容

python 复制代码
import turtle

turtle.speed(40)
turtle.penup()
turtle.goto(-175, 50 * math.sin((-175 / 100 * 2 * math.pi)))
turtle.pendown()
for x in range(-175, 176):
    turtle.goto(x, 50 * math.sin((x / 100 * 2 * math.pi)))

turtle.penup()
turtle.goto(-300, 0)
turtle.pendown()
turtle.goto(300, 0)
turtle.penup()
turtle.goto(0, 300)
turtle.pendown()
turtle.goto(0, -300)
turtle.penup()
turtle.goto(-100, -15)
turtle.write("-2\u03c0")
turtle.goto(100, -15)
turtle.write("2\u03c0")
turtle.hideturtle()
turtle.done()

今天吃火锅,早上练完瑜伽88.3到87.5 现在89.3.火锅粉丝肉片各种蔬菜,还有可乐。我的减肥呀

相关推荐
HY小海6 分钟前
【C++】AVL树实现
开发语言·数据结构·c++
workflower9 分钟前
Fundamentals of Architectural Styles and patterns
开发语言·算法·django·bug·结对编程
Roc-xb11 分钟前
ModuleNotFoundError: No module named ‘conda_token‘
开发语言·python·conda
weixin_5259363326 分钟前
部分Spark SQL编程要点
大数据·python·sql·spark
Xyz996_27 分钟前
python编程基础知识
python
人工干智能1 小时前
Python 开发中:`.ipynb`(Jupyter Notebook 文件)和 `.py`(Python 脚本文件)
开发语言·python·jupyter
woshihonghonga1 小时前
Jupyter Notebook单元格输出换行问题解决
ide·python·jupyter
~~李木子~~1 小时前
Jupyter Notebook(ipynb)转 Python(py)文件
python·jupyter
ERROR_LESS1 小时前
【ADS-1】【python基础-1】jupyter notebook环境极简搭建
python·jupyter
Jay-juice1 小时前
QT信号与槽
开发语言·qt