saltar al contenido principal
paste
bin
.ca
type · paste · share
⌘
K
Familia
La familia bin
pastebin.ca
centro
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
Iniciar sesión
?
← volver a la publicación
›
Editar / bifurcar
Publicación sin título
#8TEJPb32mH
public / public
nueva versión
anónimo
creado 6 days ago
Caduca en 1 day
1.6 KB
sintaxis:
text
Tus cambios crean una nueva publicación enlazada a esta — la original no se toca.
nueva versión
Tus cambios crean una nueva publicación enlazada a esta — la original no se toca.
Título (opcional)
Nombre de archivo
Sintaxis
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
Visibilidad
Feed público
Acceso
public
Caduca
7 días
10 min
1 hora
1 día
7 días
30 días
90 días
personalizada…
Caducidad personalizada
Nota de cambio
(opcional)
Esta publicación aparecerá en el feed público. Cambia Visibilidad si solo quieres compartirla por enlace.
Crear nueva versión
Cancelar
Pegar o escribir…
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()