カメを正方形の特定の領域に重ねるにはどうすればよいですか?

PKPython

だから私は学校とのプロジェクトのためにカメに精通しなければなりませんでした。私は基本的に、正方形を重ねること以外に、教授が求めたすべてのものを手に入れました。私の広場

しかし、彼は正方形がこのように重なることを望んでいます

Profsquares

私はこれをまったく再現することができませんでした。それらは、簡単に解決するためにコードに投入する必要があるものかどうか疑問に思っています。

これが私のコードです

import turtle #Imports the 'turtle module' which allows intricate shapes and pictures to be drawn
my_turtle_pos = (10 , 10)
def square(my_turtle,x,y,length) : #I set up a function that helps me determine the square

    my_turtle.penup() #Picks 'up' the turtle pen
    my_turtle.setposition(x-length/2,y-length/2) #Helps set positon
    my_turtle.pendown() #Puts 'down' the turtle pen
    my_turtle.color('black','red') #Allows black outline, with red filling
    my_turtle.begin_fill() #Starts the filling of red and helps remember the starting point for a filled area
    my_turtle.forward(length) #Moves the turtle by the specified amount 'length'
    my_turtle.left(90) #Moves the turtle by given amount '90'
    my_turtle.forward(length)
    my_turtle.left(90)
    my_turtle.forward(length)
    my_turtle.left(90)
    my_turtle.forward(length)
    my_turtle.left(90)
    my_turtle.end_fill() #Stops filling with red, which will close with the current color

def graphic_pattern(my_turtle,x,y,length,times): #recursive function
    if times <= 0:  #This just tells us how many 'times' it needs to repeat till given amount
        return
    newSize = length/2.2 #This will grab the new size
    graphic_pattern(my_turtle,x-length/2,y-length/2,newSize,times-1) #Functions to help with writing 'smaller' squares
    graphic_pattern(my_turtle,x-length/2,y+length/2,newSize,times-1)
    graphic_pattern(my_turtle,x+length/2,y-length/2,newSize,times-1)
    graphic_pattern(my_turtle,x+length/2,y+length/2,newSize,times-1)
    square(my_turtle,x,y,length)


my_turtle = turtle.Turtle(shape="arrow") #You can use differen't shapes for the turtle, I chose arrow, though the turtle was cool :)
my_turtle.speed(100) #I am not sure how fast the turtle can go, I just chose 100 cause it went by quicker.

graphic_pattern(my_turtle,3,0,300,4) #Example pattern stated from homework assignment.

ペンが最初に正方形を描くところと関係があると思います。ご入力いただきありがとうございます。

Ehtesh Choudhury

それはあなたgraphic_pattern()square()メソッドの単純なシーケンスのように聞こえますgraphic_pattern()最初に右上を描画し、次に中央の正方形を描画し、次に残りのgraphic_pattern()呼び出しを描画することをお勧めします。

import turtle #Imports the 'turtle module' which allows intricate shapes and pictures to be drawn
my_turtle_pos = (10 , 10)
def square(my_turtle,x,y,length) : #I set up a function that helps me determine the square

    my_turtle.penup() #Picks 'up' the turtle pen
    my_turtle.setposition(x-length/2,y-length/2) #Helps set positon
    my_turtle.pendown() #Puts 'down' the turtle pen
    my_turtle.color('black','red') #Allows black outline, with red filling
    my_turtle.begin_fill() #Starts the filling of red and helps remember the starting point for a filled area
    my_turtle.forward(length) #Moves the turtle by the specified amount 'length'
    my_turtle.left(90) #Moves the turtle by given amount '90'
    my_turtle.forward(length)
    my_turtle.left(90)
    my_turtle.forward(length)
    my_turtle.left(90)
    my_turtle.forward(length)
    my_turtle.left(90)
    my_turtle.end_fill() #Stops filling with red, which will close with the current color

def graphic_pattern(my_turtle,x,y,length,times): #recursive function
    if times <= 0:  #This just tells us how many 'times' it needs to repeat till given amount
        return
    newSize = length/2.2 #This will grab the new size

    graphic_pattern(my_turtle,x+length/2,y+length/2,newSize,times-1)
    square(my_turtle,x,y,length)
    graphic_pattern(my_turtle,x-length/2,y-length/2,newSize,times-1)
    graphic_pattern(my_turtle,x-length/2,y+length/2,newSize,times-1)
    graphic_pattern(my_turtle,x+length/2,y-length/2,newSize,times-1)


my_turtle = turtle.Turtle(shape="arrow") #You can use differen't shapes for the turtle, I chose arrow, though the turtle was cool :)
my_turtle.speed(100) #I am not sure how fast the turtle can go, I just chose 100 cause it went by quicker.

graphic_pattern(my_turtle,3,0,300,4) #Example pattern stated from homework assignment.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

この正方形を壁に跳ね返らせるにはどうすればよいですか?

分類Dev

正方形の配列でいくつかの円形の領域を簡単に選択するにはどうすればよいですか?

分類Dev

CSSで正方形の正方形を取得するにはどうすればよいですか?

分類Dev

この正方形が特定の値に達した後、この正方形の方向を逆にするにはどうすればよいですか?

分類Dev

長方形の写真を正方形の写真に入れるにはどうすればよいですか?

分類Dev

この正方形のグリッドを中央に配置するにはどうすればよいですか?

分類Dev

Xamarinで子供に正方形の寸法を強制するにはどうすればよいですか?

分類Dev

Pythonで整数の正方形のリストを作成するにはどうすればよいですか?

分類Dev

CSSでテーブルの背景の正方形を削除するにはどうすればよいですか?

分類Dev

AbsoluteLayoutに正方形のレイアウトを強制するにはどうすればよいですか?

分類Dev

ncursesで正方形のシンボルを設計するにはどうすればよいですか?

分類Dev

Qt QMLで正方形のボタンを作成するにはどうすればよいですか?

分類Dev

Flutterで正方形の隆起したボタンを作成するにはどうすればよいですか?

分類Dev

ポイントの周りに正方形を合わせるにはどうすればよいですか?

分類Dev

特定の時間間隔で色が変化する正方形のプログレスバーを作成するにはどうすればよいですか?

分類Dev

グリッド内のすべての正方形を単一のforループでカバーするにはどうすればよいですか?

分類Dev

特定のCSSグリッドアイテムに完全な正方形を作成するにはどうすればよいですか?

分類Dev

QuadTreeは正方形以外の領域でどのように機能しますか?

分類Dev

CSS-2つの正方形の中央に長方形を配置するにはどうすればよいですか

分類Dev

Scenekit(ARKit)iOS 11を使用して、プログラムで指定された幅と高さのカメラ上に正方形または長方形のオーバーレイ(平面)を作成するにはどうすればよいですか?

分類Dev

常に画面の中央にあり、短い方の端に接する正方形を作成するにはどうすればよいですか?

分類Dev

色で正方形にするボタンを作成するにはどうすればよいですか?

分類Dev

特定の領域でマウスがクリックされるたびに長方形を描画するにはどうすればよいですか?

分類Dev

正方形を互いに同じレベルにするにはどうすればよいですか?

分類Dev

OpenCVとPythonを使用して長方形の画像を正方形にするにはどうすればよいですか?

分類Dev

再帰を使用せずに、正方形を互いの上にではなく、後ろに生成するにはどうすればよいですか?

分類Dev

OpenCV2でしきい値を正方形に分割するにはどうすればよいですか?

分類Dev

点が正方形の対角線上にあるかどうかを判断するにはどうすればよいですか?

分類Dev

ブートストラップの2つの列の中央に正方形のdivを中央に配置するにはどうすればよいですか?

Related 関連記事

  1. 1

    この正方形を壁に跳ね返らせるにはどうすればよいですか?

  2. 2

    正方形の配列でいくつかの円形の領域を簡単に選択するにはどうすればよいですか?

  3. 3

    CSSで正方形の正方形を取得するにはどうすればよいですか?

  4. 4

    この正方形が特定の値に達した後、この正方形の方向を逆にするにはどうすればよいですか?

  5. 5

    長方形の写真を正方形の写真に入れるにはどうすればよいですか?

  6. 6

    この正方形のグリッドを中央に配置するにはどうすればよいですか?

  7. 7

    Xamarinで子供に正方形の寸法を強制するにはどうすればよいですか?

  8. 8

    Pythonで整数の正方形のリストを作成するにはどうすればよいですか?

  9. 9

    CSSでテーブルの背景の正方形を削除するにはどうすればよいですか?

  10. 10

    AbsoluteLayoutに正方形のレイアウトを強制するにはどうすればよいですか?

  11. 11

    ncursesで正方形のシンボルを設計するにはどうすればよいですか?

  12. 12

    Qt QMLで正方形のボタンを作成するにはどうすればよいですか?

  13. 13

    Flutterで正方形の隆起したボタンを作成するにはどうすればよいですか?

  14. 14

    ポイントの周りに正方形を合わせるにはどうすればよいですか?

  15. 15

    特定の時間間隔で色が変化する正方形のプログレスバーを作成するにはどうすればよいですか?

  16. 16

    グリッド内のすべての正方形を単一のforループでカバーするにはどうすればよいですか?

  17. 17

    特定のCSSグリッドアイテムに完全な正方形を作成するにはどうすればよいですか?

  18. 18

    QuadTreeは正方形以外の領域でどのように機能しますか?

  19. 19

    CSS-2つの正方形の中央に長方形を配置するにはどうすればよいですか

  20. 20

    Scenekit(ARKit)iOS 11を使用して、プログラムで指定された幅と高さのカメラ上に正方形または長方形のオーバーレイ(平面)を作成するにはどうすればよいですか?

  21. 21

    常に画面の中央にあり、短い方の端に接する正方形を作成するにはどうすればよいですか?

  22. 22

    色で正方形にするボタンを作成するにはどうすればよいですか?

  23. 23

    特定の領域でマウスがクリックされるたびに長方形を描画するにはどうすればよいですか?

  24. 24

    正方形を互いに同じレベルにするにはどうすればよいですか?

  25. 25

    OpenCVとPythonを使用して長方形の画像を正方形にするにはどうすればよいですか?

  26. 26

    再帰を使用せずに、正方形を互いの上にではなく、後ろに生成するにはどうすればよいですか?

  27. 27

    OpenCV2でしきい値を正方形に分割するにはどうすればよいですか?

  28. 28

    点が正方形の対角線上にあるかどうかを判断するにはどうすればよいですか?

  29. 29

    ブートストラップの2つの列の中央に正方形のdivを中央に配置するにはどうすればよいですか?

ホットタグ

アーカイブ