1
+ import cv2
2
+ from ulab import numpy as np
3
+ from st7789_spi import ST7789_SPI
4
+ import time
5
+
6
+ display = ST7789_SPI (width = 240 ,
7
+ height = 320 ,
8
+ spi_id = 0 ,
9
+ pin_cs = 17 ,
10
+ pin_dc = 16 ,
11
+ rotation = 1 )
12
+
13
+ x = 0
14
+ y = 0
15
+ vx = 10
16
+ vy = 10
17
+
18
+ while True :
19
+ img = np .zeros ((240 , 320 , 3 ), dtype = np .uint8 )
20
+ img [0 :50 , :] = (255 , 0 , 0 )
21
+ img = cv2 .ellipse (img , (160 , 120 ), (100 , 50 ), 0 , 0 , 360 , (0 , 255 , 0 ), - 1 )
22
+ img = cv2 .putText (img , "Hello OpenCV!" , (50 , 200 ), cv2 .FONT_HERSHEY_SIMPLEX , 1 , (0 , 0 , 255 ), 2 )
23
+ cv2 .imshow (display , img )
24
+ key = cv2 .waitKey (1000 )
25
+
26
+ edge_img = cv2 .Canny (img , 100 , 200 )
27
+ cv2 .imshow (display , edge_img )
28
+ key = cv2 .waitKey (2000 )
29
+
30
+ img = np .zeros ((240 , 320 , 3 ), dtype = np .uint8 )
31
+ t0 = time .time ()
32
+ while time .time () - t0 < 5 :
33
+ # Update position
34
+ x += vx
35
+ y += vy
36
+ if x <= 0 or x >= 320 - 50 :
37
+ vx = - vx # Reverse direction on x-axis
38
+ if y <= 0 or y >= 240 - 50 :
39
+ vy = - vy # Reverse direction on y-axis
40
+
41
+ # Draw a square
42
+ img [y :y + 50 , x :x + 50 ] = (0 , 0 , 255 )
43
+
44
+ cv2 .imshow (display , img )
45
+
46
+ # Clear the square area for the next frame
47
+ img [y :y + 50 , x :x + 50 ] = (0 , 0 , 0 )
0 commit comments