使用python画一个**10环圆靶**

该博客展示了如何利用Python的OpenCV库创建一个10环圆靶图像。通过定义不同环数的半径和颜色,代码依次绘制了从10环到1环的同心圆,并在靶心外圈标记了数字以表示环数。最后,程序显示并保存了生成的圆靶图像。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

10环圆靶

使用python画一个10环圆靶

在这里插入图片描述

import cv2
import numpy as np
i=11
dot_red=(300,300)   #圆心
black=(0,0,0)       #黑色
red = (0, 0, 255)   #红色
white=(255,255,255) #白色
blue=(255,0,0)      #蓝色
green=(0,255,0)      #绿色
gray=(185,188,178)  #灰色
font = cv2.FONT_HERSHEY_SIMPLEX #字体
yuan = np.zeros((600, 600, 3), np.uint8)
yuan[:]=255

while i>1:
    i=i-1
    #print(i)
    radius = (i*30)
    if i==10:
        cv2.circle(yuan, dot_red, radius, black, -1)
    elif i==9:
        cv2.circle(yuan, dot_red, radius, white, 1)
    elif i==8:
        cv2.circle(yuan, dot_red, radius, gray, -1)
    elif i==7:
        cv2.circle(yuan, dot_red, radius, black, 1)
    elif i==6:
        cv2.circle(yuan, dot_red, radius, blue, -1)
    elif i==5:
        cv2.circle(yuan, dot_red, radius, white, 1)
    elif i==4:
        cv2.circle(yuan, dot_red, radius, red, -1)
    elif i==3:
        cv2.circle(yuan, dot_red, radius, white, 1)
    elif i==2:
        cv2.circle(yuan, dot_red, radius, green, -1)
    elif i==1:
        cv2.circle(yuan, dot_red, radius, red, 1)

#显示字
a=1
b=1
x1 = 9
y1 = 310
x2=290
y2=27
while a>0:
    text = '%d' % a
    cv2.putText(yuan, text=text, org=(x1, y1), fontFace=font, fontScale=0.9, color=(255, 255, 255),
                thickness=1)  # text,
    if a == 10:
        a=a+0
    else:
        cv2.putText(yuan, text=text, org=(x2, y2), fontFace=font, fontScale=0.9, color=(255, 255, 255),
                thickness=1)  # text,
    x1=x1+30
    y2=y2+30
    if a==10:
        b=-1
        x1=x1+24
        y2=y2+24
    a = a + b

cv2.imshow('yuan', yuan)  # 显示图片
cv2.waitKey(0)
cv2.destroyAllWindows()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值