[MOD] alignment is messed up

This commit is contained in:
2024-11-24 15:36:28 +01:00
parent 46daf9ec93
commit dd7d2100df
7 changed files with 34 additions and 22 deletions

1
.gitignore vendored
View File

@@ -1,2 +1,3 @@
.vscode/
__pycache__
sphere_grid.egg-info

View File

@@ -1,7 +1,14 @@
# Motivations
I just like this FFX game design idea and I want to test some python tools I havent 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

View File

@@ -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

View File

@@ -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)

View File

@@ -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

View File

@@ -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)

View File

@@ -1 +1,2 @@
pyside6==6.6.1
pytest==8.3.3