Altıgen Oluşturma
unknown
python
a year ago
2.4 kB
14
Indexable
import cv2
import numpy as np
import time
width, height = 1300, 700 # Ana pencerenin genişlik ve yüksekliği
image = np.ones((height, width, 3), dtype=np.uint8) * 255
# Sabit değerler
line_color = (100, 100, 100)
line_thickness = 2
circle_color = (0, 0, 255)
radius_of_circle = 10
# Altıgen oluşturan fonksiyon
def create_hexagon(image, page_center, radius_of_hexagon):
# Altıgenin köşe noktaları
vertices_of_hexagon = []
for i in range(6):
angle = np.pi / 3 * i
x = int(page_center[0] + radius_of_hexagon * np.cos(angle))
y = int(page_center[1] + radius_of_hexagon * np.sin(angle))
vertices_of_hexagon.append((x, y))
# Köşe noktalarını line ile birleştir
for i in range(len(vertices_of_hexagon)):
start_point = vertices_of_hexagon[i]
end_point = vertices_of_hexagon[(i + 1) % len(vertices_of_hexagon)] # Son noktadan ilk noktaya dönmek için mod kullanıldı
cv2.line(image, start_point, end_point, line_color, line_thickness)
# Köşelere circle koy
for vertex in vertices_of_hexagon:
cv2.circle(image, vertex, radius_of_circle, circle_color, thickness=-1)
# Altıgenleri büyülterek çoğaltan fonksiyon
def period(image, start_time, program_time, waiting_time, radius_of_hexagon):
# pencereden taşmaması için
if height < width:
number_of_hexagon = height // (radius_of_hexagon * 2) + 1
else:
number_of_hexagon = width // (radius_of_hexagon * 2) + 1
for i in range(number_of_hexagon):
create_hexagon(image, (width // 2, height // 2), i * radius_of_hexagon)
cv2.imshow('Hexagon', image)
cv2.waitKey(waiting_time)
if time.time() - start_time > program_time:
return True
# pencere dolunca temizliyoruz
image[:] = 255
cv2.imshow('Hexagon', image)
return False
# program_time programın ne kadar çalışacağı süresidir
# waiting_time yeni şeklin oluşma süresidir
# program time saniye türünden, waiting time ise ms türünden olmalı
def program(program_time=10, waiting_time=500):
start_time = time.time()
finish = False
while not finish:
finish = period(image, start_time, program_time, waiting_time, 50)
if __name__ == "__main__":
cv2.imshow('Hexagon', image)
program(10, 500)
cv2.waitKey(0)
cv2.destroyAllWindows()
Editor is loading...
Leave a Comment