0% found this document useful (0 votes)
8 views5 pages

py动态蛇

The document is a Python script that uses the turtle graphics library to create a dynamic drawing of a colorful snake with various patterns. It includes functions to draw the snake, its eyes, tongue, and additional decorative patterns like spirals and zigzags. The main function orchestrates the drawing process and displays the completed artwork.

Uploaded by

yi410329
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views5 pages

py动态蛇

The document is a Python script that uses the turtle graphics library to create a dynamic drawing of a colorful snake with various patterns. It includes functions to draw the snake, its eyes, tongue, and additional decorative patterns like spirals and zigzags. The main function orchestrates the drawing process and displays the completed artwork.

Uploaded by

yi410329
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

# creative_snake.

py - 创意蟒蛇绘制程序
import turtle
import time
import random

def setup_canvas():
"""设置画布"""
turtle.setup(900, 700, 200, 200)
turtle.bgcolor("midnight blue")
turtle.title("创意蟒蛇绘制 - 动态彩虹蛇")
turtle.speed(0)
turtle.hideturtle()

def draw_creative_snake():
"""绘制创意蟒蛇"""
print("开始绘制创意蟒蛇...")

# 彩虹颜色渐变
colors = ["red", "orange", "yellow", "lime", "cyan", "blue", "purple", "magenta",
"hot pink"]

# 设置起始位置
turtle.penup()
turtle.goto(-350, 0)
turtle.pendown()
turtle.pensize(30)
turtle.seth(0)

# 绘制蛇身 - 创意弯曲
for i in range(10):
# 选择颜色
color = colors[i % len(colors)]
turtle.pencolor(color)

# 创意弯曲模式
if i % 3 == 0:
# S 形弯曲
turtle.circle(80, 90)
turtle.circle(-40, 90)
elif i % 3 == 1:
# 波浪形弯曲
turtle.circle(60, 120)
turtle.circle(-60, 120)
else:
# 螺旋形弯曲
turtle.circle(50, 180)
turtle.circle(-30, 60)

# 动态显示延迟
time.sleep(0.4)

# 随机改变笔的粗细
turtle.pensize(random.randint(25, 40))

# 绘制蛇头
turtle.pencolor("gold")
turtle.pensize(45)
turtle.circle(70, 60)

# 绘制眼睛
draw_eyes()

# 绘制舌头
draw_tongue()

def draw_eyes():
"""绘制蛇眼"""
# 左眼
turtle.penup()
turtle.goto(turtle.xcor() + 20, turtle.ycor() + 20)
turtle.pendown()
turtle.pencolor("black")
turtle.pensize(10)
turtle.circle(8)

# 右眼
turtle.penup()
turtle.goto(turtle.xcor() + 30, turtle.ycor())
turtle.pendown()
turtle.circle(8)

# 眼睛高光
turtle.penup()
turtle.goto(turtle.xcor() - 5, turtle.ycor() + 5)
turtle.pendown()
turtle.pencolor("white")
turtle.pensize(3)
turtle.circle(2)
def draw_tongue():
"""绘制蛇舌"""
turtle.penup()
turtle.goto(turtle.xcor() + 40, turtle.ycor() - 10)
turtle.pendown()
turtle.pencolor("red")
turtle.pensize(8)
turtle.seth(0)

# 绘制分叉舌头
turtle.forward(30)
turtle.left(30)
turtle.forward(15)
turtle.backward(15)
turtle.right(60)
turtle.forward(15)

def draw_spiral_pattern():
"""绘制螺旋图案"""
print("绘制螺旋装饰...")
turtle.clear()
turtle.penup()
turtle.goto(0, 0)
turtle.pendown()
turtle.pensize(20)

# 螺旋颜色渐变
for i in range(20):
r = int(255 * (1 - i/20))
g = int(255 * (i/20))
b = int(255 * (1 - i/20))
turtle.pencolor(r/255, g/255, b/255)

turtle.circle(60 + i*3, 90)


time.sleep(0.2)

def draw_zigzag_pattern():
"""绘制之字形图案"""
print("绘制之字形装饰...")
turtle.clear()
turtle.penup()
turtle.goto(-200, 100)
turtle.pendown()
turtle.pensize(25)
turtle.seth(0)

for i in range(8):
if i % 2 == 0:
turtle.pencolor("lime")
else:
turtle.pencolor("hot pink")

turtle.forward(80)
turtle.right(90)
turtle.forward(50)
turtle.left(90)
turtle.forward(80)
turtle.left(90)
turtle.forward(50)
turtle.right(90)

time.sleep(0.3)

def main():
"""主函数"""
setup_canvas()

# 绘制主要蟒蛇
draw_creative_snake()
time.sleep(2)

# 绘制装饰图案
draw_spiral_pattern()
time.sleep(2)

draw_zigzag_pattern()
time.sleep(2)

# 最终组合效果
print("绘制最终创意组合...")
turtle.clear()
turtle.penup()
turtle.goto(-250, 0)
turtle.pendown()
turtle.pensize(30)

# 绘制复杂的蛇形图案
for i in range(15):
color = ["red", "orange", "yellow", "green", "blue", "purple"][i % 6]
turtle.pencolor(color)
turtle.circle(50, 100)
turtle.circle(-25, 50)
time.sleep(0.3)

print("创意蟒蛇绘制完成!")
turtle.done()

if __name__ == "__main__":
main()

You might also like