描画フラグ
- 図書館:補助は、業務の一部を行う作業の重複を減らし、コードや複雑さの量を減らします。ホイールを作ることなく、様々な操作の良好なカプセル化は、繰り返されます。
- タートルグラフィックスライブラリ
- ジャンゴフラスコ竜巻楽屋生産拠点
- numpyのデータ分析パンダ
- scipyのダウンロード科学計算
- pygameの作るゲーム
- tensorflow pytorch keras人工知能
- pyspark pyhiveビッグデータ
- pymysqlデータベース
- 他のPythonプログラミング言語と比較すると、変数の型は同じです。(引用符で3複数行の文字列で表されます)
- リストファイル(データは、頻繁に変化する読み出し速度が比較的遅いです)
- 辞書辞書(キーと値のペア、キーは、ハッシュキーが不変オブジェクトです)
- タプルタプル(データが変化しない、そのような識別番号などのデータ、様々な存在となり、高速なデータの読み出し)
- セットコレクション
Pythonのロジック・ステートメント
- 条件文の場合
- ネストされたステートメント
- forループ
機能
- DEF関数を表し
画像処理
- シングルチャネル:黒とグレー/白
- デュアルチャンネル:RGB
--turtleシンプルなグラフィックスライブラリのPythonライブラリを使用するための実用的な操作
いくつかの一般的な方法
- ブラシの太さを設定pensize(調整パラメータ)
- pencolorペンカラーセット(調整パラメータ)
- 前進するために転送する(100個のピクセル)
- 右の現在の位置から右折
- 左ターンの現在の位置から左に
- ブラシの回転速度設定
- 描画を終了するには、彼のブラシをダウンPENUP
ループ--for Pythonの文
範囲のiについて()iは0から整数変数であります
"""
用Python的turtle模块绘制国旗
"""
import turtle
def draw_rectangle(x, y, width, height):
"""绘制矩形"""
turtle.goto(x, y)
turtle.pencolor('red')
turtle.fillcolor('red')
turtle.begin_fill()
for i in range(2):
turtle.forward(width)
turtle.left(90)
turtle.forward(height)
turtle.left(90)
turtle.end_fill()
def draw_star(x, y, radius):
"""绘制五角星"""
turtle.setpos(x, y)
pos1 = turtle.pos()
turtle.circle(-radius, 72)
pos2 = turtle.pos()
turtle.circle(-radius, 72)
pos3 = turtle.pos()
turtle.circle(-radius, 72)
pos4 = turtle.pos()
turtle.circle(-radius, 72)
pos5 = turtle.pos()
turtle.color('yellow', 'yellow')
turtle.begin_fill()
turtle.goto(pos3)
turtle.goto(pos1)
turtle.goto(pos4)
turtle.goto(pos2)
turtle.goto(pos5)
turtle.end_fill()
def main():
"""主程序"""
#设置画笔速度
turtle.speed(12)
# 抬起笔
turtle.penup()
x, y = -270, -180
# 画国旗主体
width, height = 540, 360
draw_rectangle(x, y, width, height)
# 画大星星
pice = 22
center_x, center_y = x + 5 * pice, y + height - pice * 5
turtle.goto(center_x, center_y)
turtle.left(90)
turtle.forward(pice * 3)
turtle.right(90)
draw_star(turtle.xcor(), turtle.ycor(), pice * 3)
x_poses, y_poses = [10, 12, 12, 10], [2, 4, 7, 9]
# 画小星星
for x_pos, y_pos in zip(x_poses, y_poses):
turtle.goto(x + x_pos * pice, y + height - y_pos * pice)
turtle.left(turtle.towards(center_x, center_y) - turtle.heading())
turtle.forward(pice)
turtle.right(90)
draw_star(turtle.xcor(), turtle.ycor(), pice)
# 隐藏海龟
turtle.ht()
# 显示绘图窗口
turtle.mainloop()
main()