Untitled

mail@pastecode.io avatar
unknown
plain_text
9 days ago
3.3 kB
2
Indexable
Never
import cv2
import numpy as np
import time

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_square_with_corners(canvas, center, size):
    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), 3)
    return top_left, bottom_right

def draw_corners(canvas, corners):
    for point in corners:
        cv2.circle(canvas, point, 5, (0, 255, 0), -1)

def buyuyen_sekil(sekil_turu, genisleme_hizi, sure):
    canvas = create_canvas()
    center = (canvas.shape[1] // 2, canvas.shape[0] // 2)
    draw_center_circle(canvas, center)

    baslangic_zamani = time.time()

    while time.time() - baslangic_zamani < sure:
        size = 50
        max_size = min(canvas.shape[0], canvas.shape[1]) - 50

        while size <= max_size:
            new_canvas = create_canvas()
            draw_center_circle(new_canvas, center)

            current_size = size
            while current_size >= 50:
                if sekil_turu == 'kare':
                    top_left = (center[0] - current_size // 2, center[1] - current_size // 2)
                    bottom_right = (center[0] + current_size // 2, center[1] + current_size // 2)
                elif sekil_turu == 'dikdortgen':
                    top_left = (center[0] - current_size // 2, center[1] - int(current_size * 0.3))
                    bottom_right = (top_left[0] + current_size, top_left[1] + int(current_size * 0.6))

                cv2.rectangle(new_canvas, top_left, bottom_right, (0, 0, 0), 3)

                current_size -= 50

            # Köşe noktalarını çiz
            corners = [top_left, (top_left[0], bottom_right[1]), (bottom_right[0], top_left[1]), bottom_right]
            draw_corners(new_canvas, corners)

            cv2.imshow("Buyuyen Sekil", new_canvas)
            if cv2.waitKey(genisleme_hizi) & 0xFF == 27:
                cv2.destroyAllWindows()
                return

            size += 50

        # En son büyük karenin/dikdörtgenin köşelerini göster
        if sekil_turu == 'kare':
            final_top_left = (center[0] - max_size // 2, center[1] - max_size // 2)
            final_bottom_right = (center[0] + max_size // 2, center[1] + max_size // 2)
        elif sekil_turu == 'dikdortgen':
            final_top_left = (center[0] - max_size // 2, center[1] - int(max_size * 0.3))
            final_bottom_right = (final_top_left[0] + max_size, final_top_left[1] + int(max_size * 0.6))

        final_corners = [final_top_left, (final_top_left[0], final_bottom_right[1]), 
                         (final_bottom_right[0], final_top_left[1]), final_bottom_right]
        draw_corners(canvas, final_corners)

    cv2.imshow("Buyuyen Sekil", canvas)
    cv2.waitKey(0)
    cv2.destroyAllWindows()

# Fonksiyonu çağır
buyuyen_sekil(sekil_turu='kare', genisleme_hizi=1000, sure=60)  # Kare çizimi için
buyuyen_sekil(sekil_turu='dikdortgen', genisleme_hizi=100, sure=300)  # Dikdörtgen çizimi için
Leave a Comment