海龟基础教学(一)——画出简单图形

来了来了兄弟们,前2篇试发文章还行不?今天开更海龟基础教学了!(看过试发文章的都知道,我用海龟编辑器)

首先要认识海龟:

海龟就是turtle绘图,通俗一点来讲,turtle绘图就是一个仓库,在python里面就叫库。turtle库需要import来导入,如下:

这样就把turtle库导进来了。如果我们只要部分功能呢?那就这样:

在这时forward功能就被导入进来了。这两种方式在应用时也有差别,第一种情况:

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
可以使用以下代码利用海龟图形画出火柴数字1-9: ```python import turtle # 定义火柴的函数 def draw_match(x, y): turtle.penup() turtle.goto(x, y) turtle.pendown() turtle.setheading(0) turtle.forward(20) turtle.right(90) turtle.forward(100) turtle.right(90) turtle.forward(20) turtle.right(90) turtle.forward(100) turtle.penup() # 数字1 draw_match(-100, 0) # 数字2 draw_match(0, 0) draw_match(-20, 80) draw_match(0, 100) draw_match(20, 80) draw_match(0, 0) draw_match(0, -100) # 数字3 draw_match(100, 0) draw_match(80, 80) draw_match(100, 100) draw_match(120, 80) draw_match(100, 0) draw_match(100, -100) draw_match(80, -20) draw_match(120, -20) # 数字4 draw_match(-100, -200) draw_match(-100, -100) draw_match(0, 0) draw_match(0, -100) # 数字5 draw_match(100, -200) draw_match(100, -100) draw_match(0, 0) draw_match(0, -100) draw_match(100, 0) # 数字6 draw_match(-100, -300) draw_match(-100, -200) draw_match(0, -100) draw_match(100, -200) draw_match(100, -300) draw_match(80, -320) draw_match(120, -320) # 数字7 draw_match(100, -400) draw_match(80, -320) draw_match(100, -300) draw_match(120, -320) draw_match(100, -400) draw_match(100, -500) # 数字8 draw_match(-100, -600) draw_match(-100, -500) draw_match(0, -400) draw_match(100, -500) draw_match(100, -600) draw_match(0, -700) draw_match(-100, -600) draw_match(-80, -620) draw_match(-120, -620) # 数字9 draw_match(100, -600) draw_match(100, -500) draw_match(0, -400) draw_match(-100, -500) draw_match(-100, -600) draw_match(0, -700) draw_match(80, -620) draw_match(120, -620) turtle.done() ``` 注意:以上代码只是一种实现方式,可能不是最优解。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值