small pattern and fix circle arc
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
from grid.ui.pattern import Pattern
|
from grid.ui.pattern import LargeUltimaPattern
|
||||||
|
|
||||||
|
|
||||||
class TestPattern:
|
class TestPattern:
|
||||||
def test_position(self):
|
def test_position(self):
|
||||||
p = Pattern(0, 0)
|
p = LargeUltimaPattern(0, 0)
|
||||||
assert len(p.childItems()) > 0
|
assert len(p.childItems()) > 0
|
||||||
|
|||||||
@@ -108,7 +108,10 @@ class ArcGraphicsItem(QGraphicsItem):
|
|||||||
self.angle_start = angle_start
|
self.angle_start = angle_start
|
||||||
self.angle_end = angle_end
|
self.angle_end = angle_end
|
||||||
self.draw_angle_start = int(angle_start * 16)
|
self.draw_angle_start = int(angle_start * 16)
|
||||||
self.draw_angle_end = int(angle_end * 16)
|
# must a more elegant way but it works
|
||||||
|
if angle_end == 0:
|
||||||
|
angle_end = 360
|
||||||
|
self.draw_angle_end = int(abs(angle_end-angle_start) * 16)
|
||||||
logging.debug(
|
logging.debug(
|
||||||
"arc from %s:%s of %s from %s° to %s°",
|
"arc from %s:%s of %s from %s° to %s°",
|
||||||
self.x_pos,
|
self.x_pos,
|
||||||
|
|||||||
@@ -21,9 +21,7 @@ from grid.ui.items import (
|
|||||||
|
|
||||||
|
|
||||||
class Pattern(QGraphicsItemGroup):
|
class Pattern(QGraphicsItemGroup):
|
||||||
"""Common pattern on the sphere grid"""
|
PATTERN_WIDTH = 0
|
||||||
|
|
||||||
PATTERN_WIDTH = 350
|
|
||||||
SPACE_BETWEEN_SPHERE = 60
|
SPACE_BETWEEN_SPHERE = 60
|
||||||
|
|
||||||
def __init__(self, top_left_corner_x: int, top_left_corner_y: int) -> None:
|
def __init__(self, top_left_corner_x: int, top_left_corner_y: int) -> None:
|
||||||
@@ -31,71 +29,8 @@ class Pattern(QGraphicsItemGroup):
|
|||||||
self.top_left_corner_x = top_left_corner_x
|
self.top_left_corner_x = top_left_corner_x
|
||||||
self.top_left_corner_y = top_left_corner_y
|
self.top_left_corner_y = top_left_corner_y
|
||||||
# center coordinates of the pattern
|
# center coordinates of the pattern
|
||||||
center_x = top_left_corner_x + int(self.PATTERN_WIDTH / 2)
|
self.center_x = top_left_corner_x + int(self.PATTERN_WIDTH / 2)
|
||||||
center_y = top_left_corner_y + int(self.PATTERN_WIDTH / 2)
|
self.center_y = top_left_corner_y + int(self.PATTERN_WIDTH / 2)
|
||||||
|
|
||||||
# center
|
|
||||||
|
|
||||||
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 = center_x
|
|
||||||
line_start_y = top_left_corner_y + self.SPACE_BETWEEN_SPHERE * 1.5
|
|
||||||
line_end_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
|
|
||||||
for i in range(sphere_on_circle):
|
|
||||||
self.addToGroup(
|
|
||||||
ArcGraphicsItem(
|
|
||||||
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,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
points = self.generate_circle_points(
|
|
||||||
center_x, center_y, self.SPACE_BETWEEN_SPHERE, sphere_on_circle
|
|
||||||
)
|
|
||||||
for x, y in points:
|
|
||||||
self.addToGroup(random_sphere_factory(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 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) % 360,
|
|
||||||
angle_end=int((i + 1) * 360 / sphere_on_circle) % 360,
|
|
||||||
parent=self,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
for x, y in points:
|
|
||||||
self.addToGroup(random_sphere_factory(x, y))
|
|
||||||
# self.addToGroup(
|
|
||||||
# ArcGraphicsItem(
|
|
||||||
# center_x, center_y, self.SPACE_BETWEEN_SPHERE * 2, 0, 90, self
|
|
||||||
# )
|
|
||||||
# )
|
|
||||||
|
|
||||||
def paint(
|
def paint(
|
||||||
self,
|
self,
|
||||||
@@ -120,8 +55,8 @@ class Pattern(QGraphicsItemGroup):
|
|||||||
"""generate coordinates of points on a circle equally spaced
|
"""generate coordinates of points on a circle equally spaced
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
center_x (int): center x coordinate
|
self.center_x (int): center x coordinate
|
||||||
center_y (int): center y coordinate
|
self.center_y (int): center y coordinate
|
||||||
radius (int): circle radius
|
radius (int): circle radius
|
||||||
n_points (int): number of points on the circle to generate
|
n_points (int): number of points on the circle to generate
|
||||||
|
|
||||||
@@ -138,3 +73,112 @@ class Pattern(QGraphicsItemGroup):
|
|||||||
points.append((x, y))
|
points.append((x, y))
|
||||||
|
|
||||||
return points
|
return points
|
||||||
|
|
||||||
|
|
||||||
|
class LargeUltimaPattern(Pattern):
|
||||||
|
"""Common pattern on the sphere grid"""
|
||||||
|
|
||||||
|
PATTERN_WIDTH = 350
|
||||||
|
|
||||||
|
def __init__(self, top_left_corner_x: int, top_left_corner_y: int) -> None:
|
||||||
|
super().__init__(top_left_corner_x, top_left_corner_y)
|
||||||
|
|
||||||
|
# center
|
||||||
|
|
||||||
|
line_start_x = self.center_x
|
||||||
|
line_start_y = self.center_y
|
||||||
|
line_end_x = self.center_x
|
||||||
|
line_end_y = int(self.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 = self.center_x
|
||||||
|
line_start_y = top_left_corner_y + self.SPACE_BETWEEN_SPHERE * 1.5
|
||||||
|
line_end_x = self.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(self.center_x, self.center_y))
|
||||||
|
|
||||||
|
# first cercle
|
||||||
|
sphere_on_circle = 4
|
||||||
|
for i in range(sphere_on_circle):
|
||||||
|
self.addToGroup(
|
||||||
|
ArcGraphicsItem(
|
||||||
|
x_pos=self.center_x,
|
||||||
|
y_pos=self.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,
|
||||||
|
angle_end=(360 / sphere_on_circle ),
|
||||||
|
parent=self,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
points = self.generate_circle_points(
|
||||||
|
self.center_x, self.center_y, self.SPACE_BETWEEN_SPHERE, sphere_on_circle
|
||||||
|
)
|
||||||
|
for x, y in points:
|
||||||
|
self.addToGroup(random_sphere_factory(x, y))
|
||||||
|
|
||||||
|
# second cercle
|
||||||
|
sphere_on_circle = 8
|
||||||
|
points = self.generate_circle_points(
|
||||||
|
self.center_x,
|
||||||
|
self.center_y,
|
||||||
|
self.SPACE_BETWEEN_SPHERE * 2,
|
||||||
|
sphere_on_circle,
|
||||||
|
)
|
||||||
|
for i in range(sphere_on_circle):
|
||||||
|
self.addToGroup(
|
||||||
|
ArcGraphicsItem(
|
||||||
|
x_pos=self.center_x,
|
||||||
|
y_pos=self.center_y,
|
||||||
|
width=self.SPACE_BETWEEN_SPHERE * 4,
|
||||||
|
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(random_sphere_factory(x, y))
|
||||||
|
# self.addToGroup(
|
||||||
|
# ArcGraphicsItem(
|
||||||
|
# self.center_x, self.center_y, self.SPACE_BETWEEN_SPHERE * 2, 0, 90, self
|
||||||
|
# )
|
||||||
|
# )
|
||||||
|
|
||||||
|
|
||||||
|
class SmallZPattern(Pattern):
|
||||||
|
"""Small pattern used in the sphere grid"""
|
||||||
|
|
||||||
|
PATTERN_WIDTH = 200
|
||||||
|
|
||||||
|
def __init__(self, top_left_corner_x: int, top_left_corner_y: int) -> None:
|
||||||
|
super().__init__(top_left_corner_x, top_left_corner_y)
|
||||||
|
|
||||||
|
sphere_on_circle = 6
|
||||||
|
for i in range(sphere_on_circle):
|
||||||
|
if i == 2 or i == 3:
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
self.addToGroup(
|
||||||
|
ArcGraphicsItem(
|
||||||
|
x_pos=self.center_x,
|
||||||
|
y_pos=self.center_y,
|
||||||
|
width=self.SPACE_BETWEEN_SPHERE * 2,
|
||||||
|
angle_start=(i * 360 / sphere_on_circle) % 360,
|
||||||
|
angle_end=int((i + 1) * 360 / sphere_on_circle) % 360,
|
||||||
|
parent=self,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
points = self.generate_circle_points(
|
||||||
|
self.center_x, self.center_y, self.SPACE_BETWEEN_SPHERE, sphere_on_circle
|
||||||
|
)
|
||||||
|
# Remove left and right sphere
|
||||||
|
del points[0]
|
||||||
|
del points[2]
|
||||||
|
for x, y in points:
|
||||||
|
self.addToGroup(random_sphere_factory(x, y))
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ from PySide6.QtWidgets import (
|
|||||||
QWidget,
|
QWidget,
|
||||||
)
|
)
|
||||||
|
|
||||||
from grid.ui.pattern import Pattern
|
from grid.ui.pattern import LargeUltimaPattern, SmallZPattern
|
||||||
|
|
||||||
|
|
||||||
class Window(QWidget):
|
class Window(QWidget):
|
||||||
@@ -21,14 +21,10 @@ class Window(QWidget):
|
|||||||
|
|
||||||
self.scene = QGraphicsScene(0, 0, 400, 400)
|
self.scene = QGraphicsScene(0, 0, 400, 400)
|
||||||
|
|
||||||
pp1 = Pattern(0, 0)
|
pp1 = LargeUltimaPattern(0, 0)
|
||||||
pp2 = Pattern(401, 0)
|
pp2 = SmallZPattern(401, 0)
|
||||||
pp3 = Pattern(0, 401)
|
|
||||||
pp4 = Pattern(401, 401)
|
|
||||||
self.scene.addItem(pp1)
|
self.scene.addItem(pp1)
|
||||||
self.scene.addItem(pp2)
|
self.scene.addItem(pp2)
|
||||||
self.scene.addItem(pp3)
|
|
||||||
self.scene.addItem(pp4)
|
|
||||||
|
|
||||||
view = QGraphicsView(self.scene)
|
view = QGraphicsView(self.scene)
|
||||||
view.setRenderHint(QPainter.RenderHint.Antialiasing)
|
view.setRenderHint(QPainter.RenderHint.Antialiasing)
|
||||||
|
|||||||
Reference in New Issue
Block a user