分别用python中的turtle库和opencv画蔡徐坤的代码
时间: 2024-04-29 18:23:35 浏览: 111
使用turtle库画蔡徐坤的代码:
```python
import turtle
# 设置画笔颜色和大小
turtle.pencolor("black")
turtle.pensize(5)
# 画蔡徐坤的头
turtle.circle(100)
turtle.penup()
turtle.goto(-50, 120)
turtle.pendown()
turtle.circle(20)
turtle.penup()
turtle.goto(50, 120)
turtle.pendown()
turtle.circle(20)
# 画蔡徐坤的身体
turtle.penup()
turtle.goto(-100, -100)
turtle.pendown()
turtle.forward(200)
turtle.right(90)
turtle.forward(200)
turtle.right(90)
turtle.forward(200)
turtle.right(90)
turtle.forward(200)
# 画蔡徐坤的腿
turtle.penup()
turtle.goto(-100, -200)
turtle.pendown()
turtle.right(45)
turtle.forward(100)
turtle.right(180)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(180)
turtle.forward(100)
turtle.penup()
turtle.goto(100, -200)
turtle.pendown()
turtle.left(45)
turtle.forward(100)
turtle.right(180)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(180)
turtle.forward(100)
# 隐藏画笔
turtle.hideturtle()
# 显示画布
turtle.done()
```
使用opencv画蔡徐坤的代码:
```python
import cv2
# 加载蔡徐坤的图片
img = cv2.imread("caixukun.jpg")
# 画蔡徐坤的头
cv2.circle(img, (300, 250), 100, (0, 0, 0), 5)
cv2.circle(img, (250, 200), 20, (0, 0, 0), 5)
cv2.circle(img, (350, 200), 20, (0, 0, 0), 5)
# 画蔡徐坤的身体
cv2.rectangle(img, (200, 300), (400, 500), (0, 0, 0), 5)
# 画蔡徐坤的腿
cv2.line(img, (200, 500), (300, 600), (0, 0, 0), 5)
cv2.line(img, (300, 600), (200, 700), (0, 0, 0), 5)
cv2.line(img, (400, 500), (300, 600), (0, 0, 0), 5)
cv2.line(img, (300, 600), (400, 700), (0, 0, 0), 5)
# 显示图片
cv2.imshow("Caixukun", img)
# 等待按键
cv2.waitKey(0)
# 释放内存
cv2.destroyAllWindows()
```
阅读全文