擅长:python、mysql、java
<p>此代码将绘制任意点数大于5的星。</p>
<pre><code>def star(size, points):
t.speed(-1)
t.setheading(0)
ext = 360 / points
if points % 2 == 0:
coords = []
for a in range(0, points):
t.penup()
coords.append(t.pos())
t.circle(size, ext)
for b in range(0, len(coords)):
if b % 2 == 0:
t.pendown()
t.goto(coords[b][0], coords[b][1])
else:
continue
t.goto(coords[0][0], coords[0][1])
t.penup()
for c in range(0, (len(coords) + 1)):
if c % 2 != 0:
t.goto(coords[c][0], coords[c][1])
t.pendown()
else:
continue
t.goto(coords[1][0], coords[1][1])
else:
angle = 180 - (180 / points)
t.forward(size)
t.right(angle)
</code></pre>