Day 6

7731 ワード

ペッキーコードの再現とは
turtle図面の基礎知識:1.キャンバスキャンバス(canvas)キャンバスはturtleが描画領域を展開するもので、そのサイズと初期位置1.1を設定してキャンバスサイズturtleを設定することができます.screensize(canvwidth=None,canvheight=None,bg=None)パラメータは、キャンバスの幅(単位画素)、高さ、背景色などです.
turtle.screensize(800, 600, "green")
turtle.screensize() #      (400, 300)

パラメータ:width,height:入力幅と高さが整数の場合、画素を表します.小数点以下の場合、コンピュータの画面を占める割合(startx,starty):この座標は長方形のウィンドウの左上隅の頂点の位置を表し、空の場合、ウィンドウは画面の中心にあります.
turtle.setup(width=0.6, height=0.6)
turtle.setup(width=800, height=800, startx=100, starty=100)

2.ブラシ2.1のブラシの状態キャンバス上には、既定ではキャンバスの中心となる座標軸が1つあり、座標原点上にはx軸に向かって正方向の小さな亀が1匹いる.ここでは、小さな亀について、座標の原点(位置)とx軸に向かって正の方向(方向)という2つの言葉を使います.turtle図面では、位置方向を使って小さな亀(ブラシ)の状態を記述します.2.2ブラシの属性ブラシ(ブラシの属性、色、線の幅)
  • turtle.pensize():ブラシの幅を設定します.
  • turtle.pencolor(); パラメータが入力されていない場合は、現在のブラシ色を返します.入力パラメータは、「green」、「red」などの文字列、RGB 3メタグループ、
  • などのブラシ色を設定します.
    >>> pencolor('brown')
        >>> tup = (0.2, 0.8, 0.55)
        >>> pencolor(tup)
        >>> pencolor()
        '#33cc8c'
    
  • turtle.speed(speed):ブラシの移動速度を設定し、ブラシの描画速度範囲[0,10]の整数を設定します.数字が大きいほど速い2.3描画コマンドはウミガメの描画を操作するコマンドがたくさんあります.これらのコマンドは3つに分けることができます.1つはモーションコマンド、1つはブラシ制御コマンド、もう1つはグローバル制御コマンド(1)ブラシモーションコマンドです.
    コマンド#コマンド#
    説明
    turtle.forward(distance)
    現在のブラシ方向にdistanceピクセル長を移動
    turtle.backward(distance)
    現在のブラシの反対方向にdistanceピクセルの長さを移動
    turtle.right(degree)
    時計回りにdegree°移動
    turtle.left(degree)
    反時計回りにdegree°移動
    turtle.pendown()
    移動時にグラフィックを描画します.デフォルトでは描画も行います.
    turtle.goto(x,y)
    ブラシを座標x,yの位置に移動
    turtle.penup()
    移動時にグラフィックを描画せず、ペンを持ち上げ、別の場所で描画する場合に使用します.
    turtle.speed(speed)
    ブラシの描画速度範囲[0,10]の整数
    turtle.circle()
    円を描く、半径は正(負)で、中心がブラシの左側(右側)に円を描くことを表します.
    (2)ブラシ制御コマンド:
    コマンド#コマンド#
    説明
    turtle.pensize(width)
    図形描画時の幅
    turtle.pencolor()
    ブラシの色
    turtle.fillcolor(colorstring)
    図面の塗りつぶし色を描画するには
    turtle.color(color1, color2)
    pencolor=color 1、fillcolor=color 2を同時に設定
    turtle.filling()
    現在充填されているかどうかを返します
    turtle.begin_fill()
    図面の塗りつぶしを開始する準備
    turtle.end_fill()
    充填完了;
    turtle.hideturtle()
    矢印表示を隠す;
    turtle.showturtle()
    hideturtle()関数に対応
    (3)グローバル制御コマンド
    コマンド#コマンド#
    説明
    turtle.clear()
    turtleウィンドウを空にしますが、turtleの位置と状態は変わりません.
    turtle.reset()
    ウィンドウを空にし、turtleステータスを開始ステータスにリセット
    turtle.undo()
    前のturtleアクションを取り消します
    turtle.isvisible()
    現在のturtleが表示されているかどうかを返します
    stamp()
    現在のグラフィックのコピー
    turtle.write(s[,font=("font-name",font_size,"font_type")])
    テキストを書く、sはテキストの内容で、fontはフォントのパラメータで、中はそれぞれフォントの名前、大きさとタイプです;fontはオプションで、fontのパラメータもオプションです.
    **3. 命令詳細**3.1 turtle.circle(radius,extent=None,steps=None)記述:所定の半径で円パラメータを描く:radius(半径);半径は正(負)で、円心がブラシの左側(右側)に円extent(弧)を描くことを表す.steps(optional)(半径radiusの円の内接正多角形、多角形の辺数steps)
    例:circle(50)#丸;circle(50,steps=3)#三角形;circle(120,180)#半円原文:https://www.cnblogs.com/nowgood/p/turtle.htmlブタのペッキーを描く
    from turtle import*
    
    def nose(x,y):#   (   :      )
     penup()#   
     goto(x,y)#  
     pendown()#  ,   
     setheading(-30)#         to_angle/   (0- 、90- 、180- 、270- )
     begin_fill()#        
     a=0.4
     for i in range(120):
        if 0<=i<30 or 60<=i<90:
            a=a+0.08
            left(3) #   3 
            forward(a) #   a   
        else:
            a=a-0.08
            left(3)
            forward(a)
     end_fill()#    
     penup()
     setheading(90)
     forward(25)
     setheading(0)
     forward(10)
     pendown()
     pencolor(255,155,192)#    
     setheading(10)
     begin_fill()
     circle(5)
     color(160,82,45)#     pencolor fillcolor
     end_fill()
    
    penup()
    setheading(0)
    forward(20)
    pendown()
    pencolor(255,155,192)
    setheading(10)
    begin_fill()
    circle(5)
    color(160,82,45)
    end_fill()
    
    
    def head(x,y):#   
      color((255,155,192),"pink")
      penup()
      goto(x,y)
      setheading(0)
      pendown()
      begin_fill()
      setheading(180)
      circle(300,-30)
      circle(100,-60)
      circle(80,-100)
      circle(150,-20)
      circle(60,-95)
      setheading(161)
      circle(-300,15)
      penup()
      g oto(-100,100)
      pendown()
      setheading(-30)
      a=0.4
      for i in range(60):
        if 0<=i<30 or 60<=i<90:
            a=a+0.08
            lt(3) #   3 
            fd(a) #   a   
        else:
            a=a-0.08
            lt(3)
            fd(a)
        end_fill()
    
    
    def ears(x,y): #  
     color((255,155,192),"pink")
     penup()
     goto(x,y)
     pendown()
     begin_fill()
     setheading(100)
     circle(-50,50)
     circle(-10,120)
     circle(-50,54)
     end_fill()
    
     penup()
     setheading(90)
     forward(-12)
     setheading(0)
     forward(30)
     pendown()
     begin_fill()
     setheading(100)
     circle(-50,50)
     circle(-10,120)
     circle(-50,56)
     end_fill()
    
    
    def eyes(x,y):#             
    	color((255,155,192),"white")
    	penup()
    	setheading(90)
    	forward(-20)
    	setheading(0)
    	forward(-95)
    	pendown()
    	begin_fill()
    	circle(15)
    	end_fill()
    
    	color("black")
    	penup()
    	setheading(90)
    	forward(12)
    	setheading(0)
    	forward(-3)
    	pendown()
    	begin_fill()
    	circle(3)
    	end_fill()
    
    	color((255,155,192),"white")
    	penup()
    	seth(90)
    	forward(-25)
    	seth(0)
    	forward(40)
    	pendown()
    	begin_fill()
    	circle(15)
    	end_fill()
    
    	color("black")
    	penup()
    	setheading(90)
    	forward(12)
    	setheading(0)
    	forward(-3)
    	pendown()
    	begin_fill()
    	circle(3)
    	end_fill()
    
    
    def cheek(x,y):#            
    	color((255,155,192))
    	penup()
    	goto(x,y)
    	pendown()
    	setheading(0)
    	begin_fill()
    	circle(30)
    	end_fill()
    
    
    def mouth(x,y): #            
    	color(239,69,19)
    	penup()
    	goto(x,y)
    	pendown()
    	setheading(-80)
    	circle(30,40)
    	circle(40,80)
    
    def body(x,y):#             
    	color("red",(255,99,71))
    	penup()
    	goto(x,y)
    	pendown()
    	begin_fill()
    	setheading(-130)
    	circle(100,10)
    	circle(300,30)
    	setheading(0)
    	forward(230)
    	setheading(90)
    	circle(300,30)
    	circle(100,3)
    	color((255,155,192),(255,100,100))
    	setheading(-135)
    	circle(-80,63)
    	circle(-150,24)
    	end_fill()
    
    
    def hands(x,y):#            
    	color((255,155,192))
    	penup()
    	goto(x,y)
    	pendown()
    	setheading(-160)
    	circle(300,15)
    	penup()
    	setheading(90)
    	forward(15)
    	setheading(0)
    	forward(0)
    	pendown()
    	setheading(-10)
    	circle(-20,90)
    
    	penup()
    	setheading(90)
    	forward(30)
    	setheading(0)
    	forward(237)
    	pendown()
    	setheading(-20)
    	circle(-300,15)
    	penup()
    	setheading(90)
    	forward(20)
    	setheading(0)
    	forward(0)
    	pendown()
    	setheading(-170)
    	circle(20,90)
    
    def foot(x,y):#            
    	pensize(10)
    	color((240,128,128))
    	penup()
    	goto(x,y)
    	pendown()
    	setheading(-90)
    	forward(40)
    	setheading(-180)
    	color("black")
    	pensize(15)
    	fd(20)
    
    	pensize(10)
    	color((240,128,128))
    	penup()
    	setheading(90)
    	forward(40)
    	setheading(0)
    	forward(90)
    	pendown()
    	setheading(-90)
    	forward(40)
    	setheading(-180)
    	color("black")
    	pensize(15)
    	fd(20)
    
    def tail(x,y):#             
    	pensize(4)
    	color((255,155,192))
    	penup()
    	goto(x,y)
    	pendown()
    	seth(0)
    	circle(70,20)
    	circle(10,330)
    	circle(70,30)
    
    def setting():          #    
    	pensize(4)
    	hideturtle()        #     (  )
    	colormode(255)      #     1.0 255.         r,g,b    0 .. cmode   
    	color((255,155,192),"pink")
    	setup(840,500)
    	speed(10)
    
    def main():
    	setting()           #  、    
    	nose(-100,100)      #  
    	head(-69,167)       # 
    	ears(0,160)         #  
    	eyes(0,140)         #  
    	cheek(80,10)        # 
    	mouth(-20,30)       # 
    	body(-32,-8)        #  
    	hands(-56,-45)      # 
    	foot(2,-177)        # 
    	tail(148,-155)      #  
    	done()
    
    if __name__ == '__main__':
    	main()
    --------------------- 
      :https://blog.csdn.net/weixin_43604754/article/details/88326637 
    ![         ](https://img-blog.csdnimg.cn/20190308194650878.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0NvZmZlZV9vZl9Ib21l,size_16,color_FFFFFF,t_70)