
Python でスマイリーフェイスを描画するには、turtle ライブラリを使用します。
1. ide を開き、ide で新しい py ファイルを作成し、空のファイルに次のコードを入力し、F5 キーを押してファイルを実行すると、スマイリーフェイスを描くことができます。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | from turtle import *
screensize(600,600)
speed(10)
#笑脸的小圆脸
pensize(5)
color('dim grey','yellow')
pu()
goto (0,-100)
begin_fill()
circle(100)
end_fill()
#腮红
#左侧
seth(90)
color('Light Pink','Light Pink')
pu()
goto (-55,-5)
pd()
begin_fill()
circle(20)
end_fill()
#右侧
color('Light Pink','Light Pink')
pu()
goto (55,-5)
pd()
begin_fill()
circle(-20)
end_fill()
#笑脸的眼睛
#左眼
color('dim grey','white')
pu()
goto (-10,22)
pd()
begin_fill()
circle(25)
end_fill()
#左瞳
color('dim grey','dim grey')
pu()
goto (-10,22)
seth(90)
pd()
begin_fill()
circle(25,-180)
end_fill()
#右眼
color('dim grey','white')
pu()
goto (10,22)
seth(90)
pd()
begin_fill()
circle(-25)
end_fill()
#右瞳
color('dim grey','dim grey')
pu()
goto (10,22)
seth(90)
pd()
begin_fill()
circle(-25,-180)
end_fill()
#笑脸的嘴巴
#左
pu()
goto (-4,-43)
seth(80)
pd()
circle(16,-200)
#右
pu()
goto (4,-43)
seth(110)
pd()
circle(-16,-185)
#连接
pu()
goto (4,-43)
seth(90)
pd()
circle(4,180)
hideturtle()
|
ログイン後にコピー
2. 実行結果は次のとおりです:

Python 関連の技術記事の詳細については、 を参照してください。 Pythonチュートリアル学習用コラム!
以上がPythonを使って笑顔を描く方法の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。