feat: finally a working super simple pattern
This commit is contained in:
@@ -2,7 +2,15 @@ import math
|
||||
|
||||
from typing import List, Tuple
|
||||
|
||||
from PySide6.QtCore import Qt
|
||||
|
||||
from PySide6.QtGui import QBrush, QPainter
|
||||
|
||||
from PySide6.QtWidgets import QGraphicsItemGroup
|
||||
from PySide6.QtWidgets import (
|
||||
QStyleOptionGraphicsItem,
|
||||
QWidget,
|
||||
)
|
||||
|
||||
from grid.ui.items import SphereGraphicsItem, ArcGraphicsItem, LineGraphicsItem
|
||||
|
||||
@@ -10,7 +18,7 @@ from grid.ui.items import SphereGraphicsItem, ArcGraphicsItem, LineGraphicsItem
|
||||
class Pattern(QGraphicsItemGroup):
|
||||
"""Common pattern on the sphere grid"""
|
||||
|
||||
PATTERN_WIDTH = 250
|
||||
PATTERN_WIDTH = 600
|
||||
SPACE_BETWEEN_SPHERE = 60
|
||||
|
||||
def __init__(self, top_left_corner_x: int, top_left_corner_y: int) -> None:
|
||||
@@ -30,22 +38,22 @@ class Pattern(QGraphicsItemGroup):
|
||||
)
|
||||
for x, y in points:
|
||||
self.addToGroup(SphereGraphicsItem(x, y))
|
||||
for i in range(sphere_on_circle):
|
||||
for i in range(sphere_on_circle-1):
|
||||
self.addToGroup(
|
||||
ArcGraphicsItem(
|
||||
center_x,
|
||||
center_y,
|
||||
self.SPACE_BETWEEN_SPHERE,
|
||||
(i * 360 / sphere_on_circle) % 360,
|
||||
((i + 1) * 360 / sphere_on_circle) % 360,
|
||||
self,
|
||||
x_pos=center_x,
|
||||
y_pos=center_y,
|
||||
width=self.SPACE_BETWEEN_SPHERE * 2,
|
||||
angle_start=(i * 360 / sphere_on_circle) % 360,
|
||||
angle_end=((i + 1) * 360 / sphere_on_circle) % 360,
|
||||
parent=self,
|
||||
)
|
||||
)
|
||||
|
||||
line_start_x = int(center_x + self.SPACE_BETWEEN_SPHERE / 2)
|
||||
line_start_y = int(center_y + self.SPACE_BETWEEN_SPHERE / 2)
|
||||
line_end_x = int(center_x + self.SPACE_BETWEEN_SPHERE / 2)
|
||||
line_end_y = int(center_y + self.SPACE_BETWEEN_SPHERE * 1.5)
|
||||
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)
|
||||
)
|
||||
@@ -57,30 +65,41 @@ class Pattern(QGraphicsItemGroup):
|
||||
)
|
||||
for x, y in points:
|
||||
self.addToGroup(SphereGraphicsItem(x, y))
|
||||
for i in range(sphere_on_circle):
|
||||
for i in range(sphere_on_circle-2):
|
||||
self.addToGroup(
|
||||
ArcGraphicsItem(
|
||||
center_x,
|
||||
center_y,
|
||||
self.SPACE_BETWEEN_SPHERE * 2,
|
||||
int(i * 360 / sphere_on_circle / 4) % 360,
|
||||
int((i + 1) * 360 / sphere_on_circle) % 360,
|
||||
self,
|
||||
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_end=int((i + 1) * 360 / sphere_on_circle) % 360,
|
||||
parent=self,
|
||||
)
|
||||
)
|
||||
self.addToGroup(
|
||||
ArcGraphicsItem(
|
||||
center_x, center_y, self.SPACE_BETWEEN_SPHERE * 2, 0, 90, self
|
||||
)
|
||||
)
|
||||
# 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))
|
||||
# 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,
|
||||
option: QStyleOptionGraphicsItem,
|
||||
widget: QWidget | None = ...,
|
||||
):
|
||||
super().paint(painter, option, widget)
|
||||
brush = QBrush(Qt.GlobalColor.gray)
|
||||
painter.setBrush(brush)
|
||||
painter.drawRect(0, 0, self.PATTERN_WIDTH, self.PATTERN_WIDTH)
|
||||
|
||||
def generate_circle_points(
|
||||
self, center_x: int, center_y: int, radius: int, n_points: int
|
||||
|
||||
Reference in New Issue
Block a user