Süre Eklendi
unknown
python
a year ago
2.3 kB
16
Indexable
import cv2
import numpy as np
import time
def dikey_zigzag(program_time, t=45, w=500):
# Parametre sınırları
w = max(100, min(w, 1000)) # Noktanın ilerleme hızı (milisaniye cinsinden, varsayılan 500ms)
t = max(1, min(t, 5 * 60)) # Programın çalışma süresi (saniye cinsinden, varsayılan 45 saniye)
canvas = np.ones((700, 700, 3), dtype="uint8") * 255
color = (220, 220, 220)
thickness = 2
start_points = [
(50, 350), (100, 50), (150, 250), (200, 50), (250, 250),
(300, 50), (350, 250), (400, 50), (450, 250), (500, 50),
(550, 250), (600, 50), (650, 350), (600, 650), (550, 450),
# (650,350) fazladan ekledim çünkü nokta oradan geçmiyordu.
(500, 650), (450, 450), (400, 650), (350, 450), (300, 650),
(250, 450), (200, 650), (150, 450), (100, 650), (50, 350)
]
end_points = [
(100, 50), (150, 250), (200, 50), (250, 250), (300, 50),
(350, 250), (400, 50), (450, 250), (500, 50), (550, 250),
(600, 50), (650, 350), (650, 350), (650, 350), (600, 650),
# Cizgilerde kayma olmasın diye (650,350) fazladan ekledim.
(550, 450), (500, 650), (450, 450), (400, 650), (350, 450),
(300, 650), (250, 450), (200, 650), (150, 450), (100, 650)
]
circle_color = (0, 0, 255)
circle_radius = 10
current_point_index = 0
current_point = start_points[current_point_index]
while True:
canvas = np.ones((700, 700, 3), dtype="uint8") * 255
for start, end in zip(start_points, end_points):
cv2.line(canvas, start, end, color, thickness)
cv2.circle(canvas, current_point, circle_radius, circle_color, -1)
cv2.imshow("lines with moving circle", canvas)
key = cv2.waitKey(w)
current_point_index = (current_point_index + 1) % len(
start_points) # nokta sayısı kadar gidip, döngüyü başa döndürür.
current_point = start_points[current_point_index]
cv2.circle(canvas, current_point, circle_radius, (255, 255, 255), -1)
if time.time() - start_time > program_time:
break
cv2.destroyAllWindows()
start_time = time.time()
program_time = 10
# Fonksiyonu çağıralım
dikey_zigzag(program_time)
Editor is loading...
Leave a Comment