Compare commits
4 Commits
2929064f4d
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| f35b1c5d0b | |||
| 5a3b637582 | |||
| d89c296d36 | |||
| 6902f07161 |
@@ -16,17 +16,19 @@ jobs:
|
|||||||
sleep 5
|
sleep 5
|
||||||
done
|
done
|
||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: galactica
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: Set up Python
|
- name: Set up Python 3.12
|
||||||
uses: actions/setup-python@v5
|
uses: actions/setup-python@v4
|
||||||
with:
|
with:
|
||||||
python-version: '3.12'
|
python-version: "3.12"
|
||||||
cache: 'pip'
|
- name: Install uv
|
||||||
- run: pip install -r requirements.txt
|
uses: astral-sh/setup-uv@v5
|
||||||
|
- name: Set up Python
|
||||||
|
run: uv python install
|
||||||
- name: Install the code linting and formatting tool Ruff
|
- name: Install the code linting and formatting tool Ruff
|
||||||
run: pip install ruff
|
run: uv build
|
||||||
- name: Lint code with Ruff
|
- name: Lint code with Ruff
|
||||||
run: ruff check --output-format=github --target-version=py39
|
run: ruff check --output-format=github --target-version=py39
|
||||||
- name: Check code formatting with Ruff
|
- name: Check code formatting with Ruff
|
||||||
|
|||||||
@@ -60,11 +60,13 @@ class AgilitySphereGraphicsItem(SphereGraphicsItem):
|
|||||||
def __init__(self, x_pos: int, y_pos: int) -> None:
|
def __init__(self, x_pos: int, y_pos: int) -> None:
|
||||||
super().__init__(x_pos, y_pos, Qt.GlobalColor.darkYellow)
|
super().__init__(x_pos, y_pos, Qt.GlobalColor.darkYellow)
|
||||||
|
|
||||||
|
|
||||||
class EmptySphereGraphicsItem(SphereGraphicsItem):
|
class EmptySphereGraphicsItem(SphereGraphicsItem):
|
||||||
def __init__(self, x_pos: int, y_pos: int) -> None:
|
def __init__(self, x_pos: int, y_pos: int) -> None:
|
||||||
self.SPHERE_WIDTH = 20
|
self.SPHERE_WIDTH = 20
|
||||||
super().__init__(x_pos, y_pos, Qt.GlobalColor.black)
|
super().__init__(x_pos, y_pos, Qt.GlobalColor.black)
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def random_sphere_factory(x_pos: int, y_pos: int) -> SphereGraphicsItem:
|
def random_sphere_factory(x_pos: int, y_pos: int) -> SphereGraphicsItem:
|
||||||
rand = random.random()
|
rand = random.random()
|
||||||
@@ -78,6 +80,7 @@ def random_sphere_factory(x_pos: int, y_pos: int) -> SphereGraphicsItem:
|
|||||||
obj = EmptySphereGraphicsItem(x_pos, y_pos)
|
obj = EmptySphereGraphicsItem(x_pos, y_pos)
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
|
|
||||||
class ArcGraphicsItem(QGraphicsItem):
|
class ArcGraphicsItem(QGraphicsItem):
|
||||||
"""Circle arc."""
|
"""Circle arc."""
|
||||||
|
|
||||||
@@ -111,7 +114,7 @@ class ArcGraphicsItem(QGraphicsItem):
|
|||||||
# must a more elegant way but it works
|
# must a more elegant way but it works
|
||||||
if angle_end == 0:
|
if angle_end == 0:
|
||||||
angle_end = 360
|
angle_end = 360
|
||||||
self.draw_angle_end = int(abs(angle_end-angle_start) * 16)
|
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,
|
||||||
|
|||||||
@@ -2,9 +2,8 @@ import math
|
|||||||
|
|
||||||
from typing import List, Tuple
|
from typing import List, Tuple
|
||||||
|
|
||||||
from PySide6.QtCore import Qt
|
|
||||||
|
|
||||||
from PySide6.QtGui import QBrush, QPainter
|
from PySide6.QtGui import QPainter
|
||||||
|
|
||||||
from PySide6.QtWidgets import QGraphicsItemGroup
|
from PySide6.QtWidgets import QGraphicsItemGroup
|
||||||
from PySide6.QtWidgets import (
|
from PySide6.QtWidgets import (
|
||||||
@@ -16,6 +15,7 @@ from grid.ui.items import (
|
|||||||
HPSphereGraphicsItem,
|
HPSphereGraphicsItem,
|
||||||
ArcGraphicsItem,
|
ArcGraphicsItem,
|
||||||
LineGraphicsItem,
|
LineGraphicsItem,
|
||||||
|
SphereGraphicsItem,
|
||||||
random_sphere_factory,
|
random_sphere_factory,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -31,6 +31,26 @@ class Pattern(QGraphicsItemGroup):
|
|||||||
# center coordinates of the pattern
|
# center coordinates of the pattern
|
||||||
self.center_x = top_left_corner_x + int(self.PATTERN_WIDTH / 2)
|
self.center_x = top_left_corner_x + int(self.PATTERN_WIDTH / 2)
|
||||||
self.center_y = top_left_corner_y + int(self.PATTERN_WIDTH / 2)
|
self.center_y = top_left_corner_y + int(self.PATTERN_WIDTH / 2)
|
||||||
|
self.external_connectors: List[SphereGraphicsItem] = []
|
||||||
|
|
||||||
|
def get_external_connectors(self) -> List[SphereGraphicsItem]:
|
||||||
|
"""Candidate spheres to connect with other patterns.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
List[SphereGraphicsItem]: List of spheres
|
||||||
|
"""
|
||||||
|
return self.external_connectors
|
||||||
|
|
||||||
|
def connect(self, other: "Pattern") -> None:
|
||||||
|
s1 = self.external_connectors[0]
|
||||||
|
s2 = other.external_connectors[1]
|
||||||
|
line_start_x = s1.x_pos + s1.SPHERE_WIDTH / 2
|
||||||
|
line_start_y = s1.y_pos + s1.SPHERE_WIDTH / 2
|
||||||
|
line_end_x = s2.x_pos + s2.SPHERE_WIDTH / 2
|
||||||
|
line_end_y = s2.y_pos + s2.SPHERE_WIDTH / 2
|
||||||
|
self.addToGroup(
|
||||||
|
LineGraphicsItem(line_start_x, line_start_y, line_end_x, line_end_y, self)
|
||||||
|
)
|
||||||
|
|
||||||
def paint(
|
def paint(
|
||||||
self,
|
self,
|
||||||
@@ -39,8 +59,8 @@ class Pattern(QGraphicsItemGroup):
|
|||||||
widget: QWidget | None = ...,
|
widget: QWidget | None = ...,
|
||||||
):
|
):
|
||||||
super().paint(painter, option, widget)
|
super().paint(painter, option, widget)
|
||||||
brush = QBrush(Qt.GlobalColor.gray)
|
# brush = QBrush(Qt.GlobalColor.gray)
|
||||||
painter.setBrush(brush)
|
# painter.setBrush(brush)
|
||||||
painter.drawRect(
|
painter.drawRect(
|
||||||
self.top_left_corner_x,
|
self.top_left_corner_x,
|
||||||
self.top_left_corner_y,
|
self.top_left_corner_y,
|
||||||
@@ -112,8 +132,8 @@ class LargeUltimaPattern(Pattern):
|
|||||||
y_pos=self.center_y,
|
y_pos=self.center_y,
|
||||||
width=self.SPACE_BETWEEN_SPHERE * 2,
|
width=self.SPACE_BETWEEN_SPHERE * 2,
|
||||||
angle_start=(i * 360 / sphere_on_circle) % 360,
|
angle_start=(i * 360 / sphere_on_circle) % 360,
|
||||||
#angle_end=((i + 1) * 360 / sphere_on_circle) % 360,
|
# angle_end=((i + 1) * 360 / sphere_on_circle) % 360,
|
||||||
angle_end=(360 / sphere_on_circle ),
|
angle_end=(360 / sphere_on_circle),
|
||||||
parent=self,
|
parent=self,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -143,7 +163,9 @@ class LargeUltimaPattern(Pattern):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
for x, y in points:
|
for x, y in points:
|
||||||
self.addToGroup(random_sphere_factory(x, y))
|
external_sphere = random_sphere_factory(x, y)
|
||||||
|
self.addToGroup(external_sphere)
|
||||||
|
self.external_connectors.append(external_sphere)
|
||||||
# self.addToGroup(
|
# self.addToGroup(
|
||||||
# ArcGraphicsItem(
|
# ArcGraphicsItem(
|
||||||
# self.center_x, self.center_y, self.SPACE_BETWEEN_SPHERE * 2, 0, 90, self
|
# self.center_x, self.center_y, self.SPACE_BETWEEN_SPHERE * 2, 0, 90, self
|
||||||
@@ -161,7 +183,7 @@ class SmallZPattern(Pattern):
|
|||||||
|
|
||||||
sphere_on_circle = 6
|
sphere_on_circle = 6
|
||||||
for i in range(sphere_on_circle):
|
for i in range(sphere_on_circle):
|
||||||
if i == 2 or i == 3:
|
if i == 2 or i == 3 or i == 5 or i == 0:
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
self.addToGroup(
|
self.addToGroup(
|
||||||
@@ -177,8 +199,22 @@ class SmallZPattern(Pattern):
|
|||||||
points = self.generate_circle_points(
|
points = self.generate_circle_points(
|
||||||
self.center_x, self.center_y, self.SPACE_BETWEEN_SPHERE, sphere_on_circle
|
self.center_x, self.center_y, self.SPACE_BETWEEN_SPHERE, sphere_on_circle
|
||||||
)
|
)
|
||||||
|
self.addToGroup(
|
||||||
|
LineGraphicsItem(
|
||||||
|
self.center_x, self.center_y, points[1][0], points[1][1], self
|
||||||
|
)
|
||||||
|
)
|
||||||
|
self.addToGroup(
|
||||||
|
LineGraphicsItem(
|
||||||
|
self.center_x, self.center_y, points[4][0], points[4][1], self
|
||||||
|
)
|
||||||
|
)
|
||||||
# Remove left and right sphere
|
# Remove left and right sphere
|
||||||
del points[0]
|
del points[0]
|
||||||
del points[2]
|
del points[2]
|
||||||
for x, y in points:
|
for x, y in points:
|
||||||
self.addToGroup(random_sphere_factory(x, y))
|
external_sphere = random_sphere_factory(x, y)
|
||||||
|
self.addToGroup(external_sphere)
|
||||||
|
self.external_connectors.append(external_sphere)
|
||||||
|
|
||||||
|
self.addToGroup(HPSphereGraphicsItem(self.center_x, self.center_y))
|
||||||
|
|||||||
@@ -1,9 +1,5 @@
|
|||||||
import logging
|
|
||||||
import sys
|
|
||||||
|
|
||||||
from PySide6.QtGui import QPainter
|
from PySide6.QtGui import QPainter
|
||||||
from PySide6.QtWidgets import (
|
from PySide6.QtWidgets import (
|
||||||
QApplication,
|
|
||||||
QGraphicsScene,
|
QGraphicsScene,
|
||||||
QGraphicsView,
|
QGraphicsView,
|
||||||
QHBoxLayout,
|
QHBoxLayout,
|
||||||
@@ -22,7 +18,8 @@ class Window(QWidget):
|
|||||||
self.scene = QGraphicsScene(0, 0, 400, 400)
|
self.scene = QGraphicsScene(0, 0, 400, 400)
|
||||||
|
|
||||||
pp1 = LargeUltimaPattern(0, 0)
|
pp1 = LargeUltimaPattern(0, 0)
|
||||||
pp2 = SmallZPattern(401, 0)
|
pp2 = SmallZPattern(351, 0)
|
||||||
|
pp1.connect(pp2)
|
||||||
self.scene.addItem(pp1)
|
self.scene.addItem(pp1)
|
||||||
self.scene.addItem(pp2)
|
self.scene.addItem(pp2)
|
||||||
|
|
||||||
@@ -34,12 +31,3 @@ class Window(QWidget):
|
|||||||
|
|
||||||
self.setLayout(vbox)
|
self.setLayout(vbox)
|
||||||
self.show()
|
self.show()
|
||||||
|
|
||||||
|
|
||||||
logging.basicConfig(
|
|
||||||
level=logging.DEBUG,
|
|
||||||
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
|
|
||||||
)
|
|
||||||
app = QApplication(sys.argv)
|
|
||||||
w = Window()
|
|
||||||
app.exec()
|
|
||||||
|
|||||||
19
main.py
Normal file
19
main.py
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import logging
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from grid.ui.window import Window
|
||||||
|
from PySide6.QtWidgets import QApplication
|
||||||
|
|
||||||
|
def main():
|
||||||
|
print("Hello from sphere-grid!")
|
||||||
|
logging.basicConfig(
|
||||||
|
level=logging.DEBUG,
|
||||||
|
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
|
||||||
|
)
|
||||||
|
app = QApplication(sys.argv)
|
||||||
|
w = Window() # noqa: F841
|
||||||
|
app.exec()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
@@ -9,3 +9,7 @@ dependencies = [
|
|||||||
"pytest==8.3.3",
|
"pytest==8.3.3",
|
||||||
"ruff==0.12.10",
|
"ruff==0.12.10",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[build-system]
|
||||||
|
requires = ["setuptools>=42"]
|
||||||
|
build-backend = "setuptools.build_meta"
|
||||||
BIN
screenshot.png
BIN
screenshot.png
Binary file not shown.
|
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 29 KiB |
2
uv.lock
generated
2
uv.lock
generated
@@ -142,7 +142,7 @@ wheels = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "sphere-grid"
|
name = "sphere-grid"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = { virtual = "." }
|
source = { editable = "." }
|
||||||
dependencies = [
|
dependencies = [
|
||||||
{ name = "pyside6" },
|
{ name = "pyside6" },
|
||||||
{ name = "pytest" },
|
{ name = "pytest" },
|
||||||
|
|||||||
Reference in New Issue
Block a user