python画史迪仔代码
时间: 2024-12-18 17:12:21 浏览: 10
Python turtle画图-史迪仔
5星 · 资源好评率100%
在Python中,要绘制史迪仔(Stitch from Lilo & Stitch),这通常涉及到动画或者图形创作,可以使用PIL(Python Imaging Library)或者更现代的库如pygame或matplotlib。下面是一个简单的例子,我们将创建一个基本的史迪仔头像作为静态图像:
```python
from PIL import Image, ImageDraw, ImageFont
# 创建基础图片
img_width = 100
img_height = 100
background_color = (255, 255, 255) # 白色背景
stitch_image = Image.new('RGB', (img_width, img_height), background_color)
# 绘制眼睛、鼻子、嘴巴等特征
draw = ImageDraw.Draw(stitch_image)
eye_size = 30
eye_color = (0, 0, 0) # 黑色
# 眼睛
left_eye = [(img_width//4, img_height//2 - eye_size), (img_width//4 + eye_size, img_height//2)]
right_eye = [(img_width*3//4, img_height//2 - eye_size), (img_width*3//4 - eye_size, img_height//2)]
draw.polygon(left_eye, fill=eye_color)
draw.polygon(right_eye, fill=eye_color)
# 鼻子
nose_tip = (img_width//2, img_height//4)
nose_line1 = (img_width//2 - eye_size // 2, img_height//4)
nose_line2 = (img_width//2 + eye_size // 2, img_height//4)
draw.line([nose_tip, nose_line1], fill=eye_color)
draw.line([nose_tip, nose_line2], fill=eye_color)
# 嘴巴
mouth_left = [(img_width//4, img_height//2 + eye_size * 1.5), (img_width//4, img_height*3//4)]
mouth_right = [(img_width*3//4, img_height//2 + eye_size * 1.5), (img_width*3//4, img_height*3//4)]
draw.rectangle(mouth_left, fill=eye_color)
draw.rectangle(mouth_right, fill=eye_color)
# 显示结果
stitch_image.show()
阅读全文