- Python
Python编圆
- 2023-6-27 21:57:48 @
我看过一个视屏说MC里面实体的影子是圆,上了课才知道,在计算机网络中是没有圆的,都是 n 边型,边数越多越像圆。
import turtle
turtle.shape('turtle')
def jump(x, y):
turtle.penup()
turtle.goto(x, y)
turtle.pendown()
def forward(l):
turtle.forward(l)
def right(a):
turtle.right(a)
def penup():
turtle.penup()
def pendown():
turtle.pendown()
def begin_fill():
turtle.begin_fill()
def fill_color(color):
turtle.color(color)
def end_fill():
turtle.end_fill()
def done():
turtle.done()
length=1
angle=0.36
i=1
while i <= 1000:
forward(length)
right(angle)
i = i + 1
这样你就能看到一只小海龟在画"圆"啦。 可能有点慢。
7 条评论
-
龙涵杰 LV 7 @ 2023-6-28 12:12:58
继续往后学,你会发现更简便的方式
-
2023-6-27 22:23:38@
更好的代码:
from wonderLang import * # 导入 wonderLand 所有内容 length = 1 # 边长为 1 angle = 0.36 # 角度为 0.36 sides = 1000 # 1000 个边 # ------------- i = 1 # 循环的 i while i <= 1000: forward(length) right(angle) i = i + 1 pause()
更更好的代码:
from wonderLang import * # 导入 wonderLand 所有内容 length = 1 # 边长为 1 angle = 0.36 # 角度为 0.36 sides = 1000 # 1000 个边 # ------------- i = 0 # 循环的 i # python 学习到后期 列表索引从 0 开始,所以建议将 i 设为 0 while i < 1000: forward(length) right(angle) i = i + 1 pause()
更更更好的代码:
from wonderLang import * # 导入 wonderLand 所有内容 length = 1 # 边长为 1 angle = 0.36 # 角度为 0.36 sides = 1000 # 1000 个边 # ------------- for i in range(sides): # for 循环 forward(length) right(angle) pause()
-
2023-6-27 22:13:48@
没下文件的用我这个
-
2023-6-27 22:10:52@
也可以直接用
from wonderLang import *
-
2023-6-27 22:06:51@
李尧老师的wonderLang可以直接import 不用再写
-
2023-6-27 22:05:32@
很棒!!! 继续加油!
-
2023-6-27 22:04:14@
大家可以看看哈,我用了李老师的wonderLang乌龟库代码,和自己变得圆代码。
- 1