pythonのtkinterのcreate_rectangleを用いて、上記のような四角形をダイアモンド状に配列して描画するプログラムを書きたいです。
以下のように四角形を四角形状に配列するところまではできたのですが、これをダイアモンド状に配置することが難しいです。アドバイス等どうぞよろしくお願い致します。
python
from tkinter import * # ウィンドウの作成 win = Tk( ) win.title( "Sample Window" ) width, height = 600, 600 win.geometry( f"{width}x{height}" ) win.attributes( "-topmost", True ) # キャンバスの作成 c = Canvas( win, width=width, height=height ) # 描画 #size = int( input("サイズ:")) size = 9 edge = 35 for n in range( size ): for m in range( size ): r = c.create_rectangle( (m+1)*edge-2 , (n+1)*edge-2, m*edge, n*edge) c.move( r, 150, 150 ) # 描画の確定 c.pack( ) # ウィンドウの制御を渡す mainloop( )
まだ回答がついていません
会員登録して回答してみよう