line on first layer then spheres
Some checks failed
CI/CD / wol (push) Has been cancelled
CI/CD / build (push) Has been cancelled

This commit is contained in:
2025-08-21 23:14:39 +02:00
parent 6a63ff5d0b
commit 552a330feb
3 changed files with 56 additions and 38 deletions

View File

@@ -1,4 +1,5 @@
import math
import random
from typing import List, Tuple
@@ -12,33 +13,46 @@ from PySide6.QtWidgets import (
QWidget,
)
from grid.ui.items import SphereGraphicsItem, ArcGraphicsItem, LineGraphicsItem
from grid.ui.items import HPSphereGraphicsItem, SphereGraphicsItem, ArcGraphicsItem, LineGraphicsItem, StrenghSphereGraphicsItem
class Pattern(QGraphicsItemGroup):
"""Common pattern on the sphere grid"""
PATTERN_WIDTH = 600
PATTERN_WIDTH = 400
SPACE_BETWEEN_SPHERE = 60
def __init__(self, top_left_corner_x: int, top_left_corner_y: int) -> None:
super().__init__()
self.top_left_corner_x = top_left_corner_x
self.top_left_corner_y = top_left_corner_y
# center coordinates of the pattern
center_x = int((top_left_corner_x + self.PATTERN_WIDTH) / 2)
center_y = int((top_left_corner_y + self.PATTERN_WIDTH) / 2)
# center
self.addToGroup(SphereGraphicsItem(center_x, center_y))
self.addToGroup(SphereGraphicsItem(0, 0))
line_start_x = center_x
line_start_y = center_y
line_end_x = center_x
line_end_y = int(center_y + self.SPACE_BETWEEN_SPHERE)
self.addToGroup(
LineGraphicsItem(line_start_x, line_start_y, line_end_x, line_end_y, self)
)
line_start_x = top_left_corner_x + center_x
line_start_y = top_left_corner_y + self.SPACE_BETWEEN_SPHERE * 1.5
line_end_x = top_left_corner_x + center_x
line_end_y = top_left_corner_y + self.SPACE_BETWEEN_SPHERE * 2.5
self.addToGroup(
LineGraphicsItem(line_start_x, line_start_y, line_end_x, line_end_y, self)
)
self.addToGroup(HPSphereGraphicsItem(center_x, center_y))
# first cercle
sphere_on_circle = 4
points = self.generate_circle_points(
center_x, center_y, self.SPACE_BETWEEN_SPHERE, sphere_on_circle
)
for x, y in points:
self.addToGroup(SphereGraphicsItem(x, y))
for i in range(sphere_on_circle-1):
for i in range(sphere_on_circle):
self.addToGroup(
ArcGraphicsItem(
x_pos=center_x,
@@ -49,47 +63,39 @@ class Pattern(QGraphicsItemGroup):
parent=self,
)
)
line_start_x = center_x
line_start_y = center_y
line_end_x = center_x
line_end_y = int(center_y + self.SPACE_BETWEEN_SPHERE)
self.addToGroup(
LineGraphicsItem(line_start_x, line_start_y, line_end_x, line_end_y, self)
points = self.generate_circle_points(
center_x, center_y, self.SPACE_BETWEEN_SPHERE, sphere_on_circle
)
for x, y in points:
if random.random() > 0.5:
self.addToGroup(SphereGraphicsItem(x, y))
else:
self.addToGroup(StrenghSphereGraphicsItem(x, y))
# second cercle
sphere_on_circle = 8
points = self.generate_circle_points(
center_x, center_y, self.SPACE_BETWEEN_SPHERE * 2, sphere_on_circle
)
for x, y in points:
self.addToGroup(SphereGraphicsItem(x, y))
for i in range(sphere_on_circle-2):
for i in range(sphere_on_circle):
self.addToGroup(
ArcGraphicsItem(
x_pos=center_x,
y_pos=center_y,
width=self.SPACE_BETWEEN_SPHERE * 4,
angle_start=int(i * 360 / sphere_on_circle / 4) % 360,
angle_start=int(i * 360 / sphere_on_circle) % 360,
angle_end=int((i + 1) * 360 / sphere_on_circle) % 360,
parent=self,
)
)
for x, y in points:
self.addToGroup(SphereGraphicsItem(x, y))
# self.addToGroup(
# ArcGraphicsItem(
# center_x, center_y, self.SPACE_BETWEEN_SPHERE * 2, 0, 90, self
# )
# )
# third cercle
# sphere_on_circle = 8
# points = self.generate_circle_points(
# center_x, center_y, self.SPACE_BETWEEN_SPHERE * 3, sphere_on_circle
# )
# for x, y in points:
# self.addToGroup(SphereGraphicsItem(x, y))
def paint(
self,
painter: QPainter,
@@ -99,10 +105,11 @@ class Pattern(QGraphicsItemGroup):
super().paint(painter, option, widget)
brush = QBrush(Qt.GlobalColor.gray)
painter.setBrush(brush)
painter.drawRect(0, 0, self.PATTERN_WIDTH, self.PATTERN_WIDTH)
painter.drawRect(self.top_left_corner_x, self.top_left_corner_y, self.PATTERN_WIDTH, self.PATTERN_WIDTH)
@staticmethod
def generate_circle_points(
self, center_x: int, center_y: int, radius: int, n_points: int
center_x: int, center_y: int, radius: int, n_points: int
) -> List[Tuple[int, int]]:
"""generate coordinates of points on a circle equally spaced