diff --git a/.gitignore b/.gitignore index 2219fba..63d07bc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .vscode/ +__pycache__ sphere_grid.egg-info \ No newline at end of file diff --git a/README.md b/README.md index 6d381e9..df63262 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,14 @@ +# Motivations + +I just like this FFX game design idea and I want to test some python tools I haven’t used in projects yet such as ruff and pytest. + +No clear roadmap, just 2D graphics fun + # Roadmap ideas - [ ] seeded RNG -- [ ] pattern: circle, line +- [ ] pattern: classic circles, line to connect far away patterns +- [ ] path finding # Tools diff --git a/grid/test/test_pattern.py b/grid/test/test_pattern.py new file mode 100644 index 0000000..29eabbe --- /dev/null +++ b/grid/test/test_pattern.py @@ -0,0 +1,7 @@ +from grid.ui.pattern import Pattern + +class TestPattern(): + + def test_position(self): + p = Pattern(500, 500) + assert len(p.childItems()) > 0 \ No newline at end of file diff --git a/grid/ui/sphere_widget.py b/grid/ui/items.py similarity index 80% rename from grid/ui/sphere_widget.py rename to grid/ui/items.py index 32f670f..9a09861 100644 --- a/grid/ui/sphere_widget.py +++ b/grid/ui/items.py @@ -21,17 +21,17 @@ class ArcGraphicsItem(QGraphicsItem): def __init__(self, x_pos: int, y_pos: int, width: int, angle_start: int, angle_end: int, parent: QGraphicsItem | None = ...): super().__init__(parent) - print(f"arc from {x_pos}:{y_pos} of {width} {angle_start}° {angle_end}°") - self.x_pos = x_pos - self.y_pos = y_pos - self.width = width - self.angle_start = angle_start - self.angle_end = angle_end + shift = int(width/2) + self.x_pos = x_pos-shift + self.y_pos = y_pos-shift + self.width = width*2 + self.angle_start = angle_start*16 + self.angle_end = angle_end*16 + print(f"arc from {self.x_pos}:{self.y_pos} of {self.width} {self.angle_start}° {self.angle_end}°") def paint(self, painter: QPainter, option: QStyleOptionGraphicsItem, widget: QWidget | None = ...) -> None: - shift = int(self.width/2) - painter.drawArc(self.x_pos-shift, self.y_pos-shift, self.width*2, - self.width*2, self.angle_start*16, self.angle_end*16) + painter.drawArc(self.x_pos, self.y_pos, self.width, + self.width, self.angle_start, self.angle_end) def boundingRect(self) -> QRectF: return QRectF(0, 0, self.x_pos, self.y_pos) diff --git a/grid/ui/pattern.py b/grid/ui/pattern.py index 10a4710..6b5f45f 100644 --- a/grid/ui/pattern.py +++ b/grid/ui/pattern.py @@ -5,12 +5,12 @@ from typing import List, Tuple from PySide6.QtWidgets import QGraphicsItemGroup from random import randint -from grid.ui.sphere_widget import SphereGraphicsItem, ArcGraphicsItem, LineGraphicsItem +from grid.ui.items import SphereGraphicsItem, ArcGraphicsItem, LineGraphicsItem class Pattern(QGraphicsItemGroup): """Common pattern on the sphere grid """ - + PATTERN_WIDTH = 250 SPACE_BETWEEN_SPHERE = 60 @@ -22,6 +22,7 @@ class Pattern(QGraphicsItemGroup): # center self.addToGroup(SphereGraphicsItem(center_x, center_y)) + self.addToGroup(SphereGraphicsItem(0, 0)) # first cercle sphere_on_circle = 4 @@ -43,8 +44,9 @@ class Pattern(QGraphicsItemGroup): 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): - # 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)) + for i in range(sphere_on_circle): + 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)) + self.addToGroup(ArcGraphicsItem(center_x, center_y, self.SPACE_BETWEEN_SPHERE*2, 0, 90, self)) # third cercle sphere_on_circle = 8 diff --git a/grid/ui/window.py b/grid/ui/window.py index 10e8b23..d2b61d8 100644 --- a/grid/ui/window.py +++ b/grid/ui/window.py @@ -18,22 +18,16 @@ class Window(QWidget): self.setWindowTitle("sphere grid") self.setGeometry(0, 0, 600, 600) - self.scene = QGraphicsScene(0, 0, 600, 400) + self.scene = QGraphicsScene(0, 0, 600, 600) - pp = Pattern(200, 100) - #for wid in pp.content: - # self.scene.addItem(wid) + pp = Pattern(300, 300) self.scene.addItem(pp) - # Define our layout. - hbox = QHBoxLayout() - view = QGraphicsView(self.scene) view.setRenderHint(QPainter.RenderHint.Antialiasing) vbox = QHBoxLayout(self) - vbox.addLayout(hbox) vbox.addWidget(view) self.setLayout(vbox) diff --git a/requirements.txt b/requirements.txt index 8e98247..629a7b4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ pyside6==6.6.1 +pytest==8.3.3 \ No newline at end of file