turtle fillcolor_使Python中的turtle模块画图两只小羊
生活随笔
收集整理的這篇文章主要介紹了
turtle fillcolor_使Python中的turtle模块画图两只小羊
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
import turtle
import time
import math as m
class Sheep(object):def __init__(self,xsize):self.t = turtle.Turtle()self.xsize = xsizet = self.t# 畫筆設置t.screen.screensize(canvwidth=1000,canvheight=500,bg='white')t.pensize(2)t.speed(10)# t.hideturtle()#初始化畫筆位置t.penup()t.setpos(self.xsize,0)t.pendown()# 設置畫筆坐標def setxy(self,x,y):t = self.tt.penup()pos_x = t.position()[0]pos_y = t.position()[1]t.setpos(pos_x + x,pos_y + y)t.pendown()def create_sheep(self):t = self.t# 羊頭self.setxy(-200,0)t.fillcolor('black')t.begin_fill()t.circle(100)t.end_fill()# 眼睛# 眼白print(t.position())self.setxy(-20,120)t.fillcolor('white')t.begin_fill()t.seth(45)t.circle(18,-280)t.seth(45)t.circle(-20,292)t.end_fill()# 眼珠self.setxy(3,12)t.fillcolor('black')t.begin_fill()t.seth(85)t.circle(10)t.seth(85)t.circle(-10)t.end_fill()# 眼心t.fillcolor('white')t.begin_fill()t.seth(85)t.circle(3)t.seth(85)t.circle(-3)t.end_fill()# 嘴self.setxy(0,-100)t.color('red')t.seth(300)t.forward(8)self.setxy(-1, 3)t.seth(0)t.circle(80,60)self.setxy(2, -2)t.seth(145)t.forward(8)t.color('black')# 耳朵self.setxy(-145,120)p1 = t.position()t.fillcolor('black')t.begin_fill()t.seth(0)t.circle(-120,20)p2 = t.position()t.setpos(p1)t.seth(60)t.circle(-30,120)t.goto(p2)t.end_fill()# 身體self.setxy(41,12)t.seth(45)t.circle(-150,100)t.pensize(5)t.seth(0)t.circle(-120,30)t.seth(60)t.circle(-15,320)t.seth(330)t.circle(-80,180)t.seth(210)t.circle(-80,90)#4條腿t.pensize(2)for leg in range(4):self.setxy(8+15*leg,0)t.seth(270)t.forward(80)t.seth(0)t.forward(8)t.seth(90)t.forward(80)#草self.setxy(-200,-80)p3 = t.position()t.color('green')t.fillcolor('green')t.begin_fill()t.seth(120)t.forward(30)t.seth(330)t.forward(30)t.seth(60)t.forward(40)t.seth(260)t.forward(45)t.setpos(p3)t.end_fill()if __name__ == '__main__':for x in (0,350):sheep = Sheep(x)sheep.create_sheep()time.sleep(5)
#Python學習交流群:973783996
PS:circle函數使用記錄
turtle.circle(radius, extent=None, steps=None)
描述: 以給定半徑畫圓
參數:
radius(半徑); 半徑為正(負),表示圓心在畫筆的左邊(右邊)畫圓
extent(弧度) (optional);
steps (optional) (做半徑為radius的圓的內切正多邊形,多邊形邊數為steps)
radius > 0,逆時針畫圓
radius < 0,順時針畫圓
extent > 0,取正方向的圓
extent < 0,取反方向的圓
總結
以上是生活随笔為你收集整理的turtle fillcolor_使Python中的turtle模块画图两只小羊的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python中递归函数写法_python
- 下一篇: 山姆会员app需要会员才能买(全国哪个城