show | version | enable_checker |
---|---|---|
step |
1.0 |
true |
- 上次研究了写字效果
- 感觉可以做一个打字练习器
- 下次玩点什么呢?🤔
import numpy as np
import cv2
import time
width = height = 300
x = y = 150
r = 0
while cv2.waitKey(1) == -1:
r = r + 1
img = np.ones((width, height, 3),np.uint8) * 255
cv2.circle(img, (x,y), r ,(255,0,0),-1)
cv2.imshow("img",img)
time.sleep(1/30)
cv2.destroyAllWindows()
- 半径从零到大
- 可以把具体参数输出出来吗?
import numpy as np
import cv2
import time
width = height = 300
x = y = 150
r = 20
while cv2.waitKey(1) == -1:
img = np.ones((width, height, 3),np.uint8) * 255
y = y + 1
cv2.putText(img,"y="+str(y),(30,80),cv2.FONT_HERSHEY_TRIPLEX,2,(0,0,255),5)
print("y=========",y)
cv2.circle(img, (x,y), r ,(0,0,0),-1)
cv2.imshow("img",img)
time.sleep(1/30)
cv2.destroyAllWindows()
- 圆心下移
- 并输出了参数
- 画面
- 控制台后台
import numpy as np
import cv2
import time
width = height = 300
x = y = 150
r = 0
isBigger = True
while cv2.waitKey(1) == -1:
if r == 100:
isBigger = False
if r == 10:
isBigger = True
if isBigger == True:
r = r + 1
else:
r = r - 1
img = np.ones((width, height, 3),np.uint8) * 255
cv2.circle(img, (x,y), r ,(0,0,255),-1)
cv2.imshow("img",img)
time.sleep(1/100)
cv2.destroyAllWindows()
- 可以控制圆形变化
- 凝视画面
- 配合呼吸
- 可以做点更复杂点的吗?
- 比如小球弹跳动画??
import numpy as np
import cv2
import time
canvas = np.zeros((300,300,3), np.uint8)
cv2.imshow("Lines",canvas)
x = 150
y = 150
for num in range(0,30):
point = (x,y)
color = np.random.randint(0,256,size=(3,)).tolist()
x = np.random.randint(0,300)
y = np.random.randint(0,300)
r = np.random.randint(1,5)
print("num:",num,":color",color,":(x,y)",(x,y),":r",r)
cv2.line(canvas,point,(x, y),color,r)
cv2.imshow("Lines",canvas)
time.sleep(1/6)
cv2.waitKey(1)
cv2.destroyAllWindows()
- 具体效果
- 能做点更有规律性的吗?
import numpy as np
import cv2
import time
import math
width = height = 300
sun_x = sun_y = 150
num = 0
while cv2.waitKey(1) == -1:
num = (num + 1) % 360
radius = num / 360 * 2 * math.pi
img = np.zeros((width, height, 3),np.uint8)
cv2.circle(img, (sun_x,sun_y), 15, (0,0,255),-1)
earth_x = int(sun_x + math.cos(radius) * 100)
earth_y = int(sun_y + math.sin(radius) * 100)
cv2.circle(img, (earth_x,earth_y), 10, (255,255,0),-1)
cv2.imshow("img",img)
time.sleep(1/100)
cv2.destroyAllWindows()
- 效果
- 能否在此基础上制作出月亮?
- 这次设置了动画效果
- 感觉可以作为变量的因素
- 颜色
- 位置
- 半径
- 时间周期
- 可以做出一个钟表吗?🤔
- 下次再说👋