メインコンテンツへスキップ
paste
bin
.ca
type · paste · share
⌘
K
ファミリー
bin ファミリー
pastebin.ca
ハブ
Share text and code with expiry and privacy controls.
imagebin.ca
Upload and share images with direct links.
filebin.ca
Drop a file and get a shareable link.
notebin.ca
Write Markdown notes with durable links.
turl.ca
Short, reputation-checked links.
attn.ca
Notifications and alerts for your services.
voicebin.ca
Record and share short voice clips.
dnsbin.ca
Inspect DNS and debug records.
ドキュメント
サインイン
?
← ペーストに戻る
›
編集 / フォーク
無題のペースト
#8TEJPb32mH
public / public
新しいバージョン
匿名
作成日 6 days ago
失効まで 1 day
1.6 KB
構文:
text
変更により、このペーストにリンクされた新しいペーストが作成されます — 元のペーストは変更されません。
新しいバージョン
変更により、このペーストにリンクされた新しいペーストが作成されます — 元のペーストは変更されません。
タイトル(任意)
ファイル名
構文
text
text
bash
c
cpp
css
diff
dockerfile
go
html
ini
java
javascript
json
kotlin
lua
makefile
markdown
nginx
php
python
ruby
rust
shellscript
sql
swift
toml
typescript
xml
yaml
可視性
パブリックフィード
アクセス
public
失効
7日
10分
1時間
1日
7日
30日
90日
カスタム…
カスタム失効
変更メモ
(任意)
このペーストはパブリックフィードに表示されます。リンクを知っている人だけに見せたい場合は可視性を変更してください。
新しいバージョンを作成
キャンセル
貼り付けるか入力…
import turtle import math def midpoint(p, q): """返回两点中点""" return ((p[0] + q[0]) / 2, (p[1] + q[1]) / 2) def midpoint_triangle(pts): """返回三角形三边中点组成的三角形(顶点顺序与原三角形一致)""" return [midpoint(pts[i], pts[(i + 1) % 3]) for i in range(3)] def draw_polygon(t, pts, fill=None, pen_color="black"): """按给定顶点绘制多边形,可选填充颜色""" t.penup() t.goto(pts[0]) t.pendown() t.pencolor(pen_color) if fill is not None: t.fillcolor(fill) t.begin_fill() for p in pts[1:]: t.goto(p) t.goto(pts[0]) if fill is not None: t.end_fill() def main(): turtle.setup(700, 600) turtle.title("嵌套正三角形") t = turtle.Turtle() t.speed(4) t.pensize(2) # 外三角形:边长 200,质心置于原点 s = 200 h = s * math.sqrt(3) / 2 # 高 T1 = [(-s / 2, -h / 3), (s / 2, -h / 3), (0, 2 * h / 3)] # 中三角形:边长为 100,顶点为外三角形三边中点 T2 = midpoint_triangle(T1) # 内三角形:边长为 50,顶点为中三角形三边中点 T3 = midpoint_triangle(T2) # 1. 画外三角形(只描边) draw_polygon(t, T1) # 2. 画中三角形并整体填充黄色 draw_polygon(t, T2, fill="yellow") # 3. 画内三角形并用背景色(白色)覆盖, # 这样中三角形中“不与内三角形重叠”的部分就留下黄色 draw_polygon(t, T3, fill="white") t.hideturtle() turtle.done() if __name__ == "__main__": main()