passer au contenu principal
paste
bin
.ca
type · paste · share
⌘
K
Famille
La famille bin
pastebin.ca
pôle
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.
Docs
Se connecter
?
← retour au collage
›
Modifier / dupliquer
Collage sans titre
#8TEJPb32mH
public / public
nouvelle version
anonyme
créé 6 days ago
Expire dans 1 day
1.6 KB
syntaxe:
text
Vos changements créent un nouveau collage lié à celui-ci — l’original reste intact.
nouvelle version
Vos changements créent un nouveau collage lié à celui-ci — l’original reste intact.
Titre (facultatif)
Nom de fichier
Syntaxe
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
Visibilité
Fil public
Accès
public
Expire
7 jours
10 min
1 heure
1 jour
7 jours
30 jours
90 jours
personnalisé…
Expiration personnalisée
Note de changement
(facultatif)
Ce collage sera affiché dans le fil public. Changez la visibilité si vous voulez seulement le partager par lien.
Créer une nouvelle version
Annuler
Collez ou tapez…
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()