Python learning about Turtle

Python learning about Turtle

Turtle learning

Graphics base:turtle
Main usage:painting
Some tips:

  • use dir(third base) can get all function in third base
  • use help(third base) can get the introduction to third base
  • use help(third base.function)can get the use of function

For example:

  • dir(turtle)
  • help(turtle)
  • help(turtle.back)

Practice project:one pig who name is peiqi

Turtle Function

  1. pensize(1-10) : the pen size

  2. hideturtle(): hide the pen

  3. colormode(1 or 255) : select mode of color divide 1 or 255 in r,g,b the three basic color

  4. color(‘type’ or ‘number-r,g,b’) : which can use two style and can mix with two color

  5. setup(width = ,height = ,startx = ,starty = ) : set canvas size and the pen where to start

  6. speed(0-10) : from 1 to 10 begin very fast and 0 is the fastest

  7. penup() | pu | up : all represent no drawing when pen start to move

  8. pendown() | pd | down : all represent put the pen down in canvas

  9. setpos(x,y) | setpostion | goto : get the pen to specific location x and y both are number

  10. setheading(angle) | seth : to adjust the angle of pen

  11. begin_fill() | end_fill : fill the color in painting

  12. left(angle) | lf : left some angle while painting

  13. forward(number) | fd : move pen forward some distance

  14. circle(r,angle,step) : to painting circle ‘r’ is radius ‘angle’ is circle length ‘step’ is calculate numbers

Turtle steps

first:set pensize | canvas size | speed | colormode before color
second: penup | pendown | setpostion
third: setheading | left | forward | circle | begin_fill | begin_end
four: mainloop

Turtle practice

import turtle as tu

#first
tu.pensize(4)
tu.setup(800,600,400,200)
tu.speed(5)
tu.colormode(255)
tu.color(205,65,160)

#second
tu.penup()
tu.setpos(20,50)
tu.pendown()
tu.begin_fill()
tu.goto(60,30)

#third
tu.setheading(90)
tu.forward(100)
tu.left(90)
tu.forward(100)
tu.end_fill()
tu.circle(20,180,5)

#four
tu.mainloop()

随手复现的图片

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值