Kutay

mail@pastecode.io avatar
unknown
plain_text
9 days ago
1.5 kB
1
Indexable
Never
import cv2
import numpy as np

def create_canvas():
    return np.ones((500, 500, 3), dtype="uint8") * 255

def draw_center_circle(canvas, center, radius=10):
    cv2.circle(canvas, center, radius, (0, 0, 0), -1) 

def draw_expanding_squares(canvas, center, max_size):
    
    size = 50
    while size < max_size: #max sizedan küçük olsun diye
        top_left = (center[0] - size // 2, center[1] - size // 2)
        bottom_right = (center[0] + size // 2, center[1] + size // 2)
        cv2.rectangle(canvas, top_left, bottom_right, (0, 0, 0), 4)  
        size += 50

    top_left = (center[0] - max_size // 2, center[1] - max_size // 2)
    bottom_right = (center[0] + max_size // 2, center[1] + max_size // 2)
    
    corner_points = [
        top_left,
        (top_left[0], bottom_right[1]),
        (bottom_right[0], top_left[1]),
        bottom_right
    ]
    for point in corner_points:
        cv2.circle(canvas, point, 8, (0, 255, 0), -1)  

def expand_squares():
    size = 50
    while True:
        canvas = create_canvas()
        center = (canvas.shape[1] // 2, canvas.shape[0] // 2)
        draw_center_circle(canvas, center)
        draw_expanding_squares(canvas, center, size)

        cv2.imshow("Canvas", canvas)

        key = cv2.waitKey(500)
        if key == 27: 
            break

        size += 50 

    cv2.destroyAllWindows()


if __name__ == "__main__":
    expand_squares()
Leave a Comment