[MOD] alignment is messed up
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1,3 @@
|
|||||||
.vscode/
|
.vscode/
|
||||||
|
__pycache__
|
||||||
sphere_grid.egg-info
|
sphere_grid.egg-info
|
||||||
@@ -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
|
# Roadmap ideas
|
||||||
|
|
||||||
- [ ] seeded RNG
|
- [ ] seeded RNG
|
||||||
- [ ] pattern: circle, line
|
- [ ] pattern: classic circles, line to connect far away patterns
|
||||||
|
- [ ] path finding
|
||||||
|
|
||||||
# Tools
|
# Tools
|
||||||
|
|
||||||
|
|||||||
7
grid/test/test_pattern.py
Normal file
7
grid/test/test_pattern.py
Normal 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
|
||||||
@@ -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 = ...):
|
def __init__(self, x_pos: int, y_pos: int, width: int, angle_start: int, angle_end: int, parent: QGraphicsItem | None = ...):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
print(f"arc from {x_pos}:{y_pos} of {width} {angle_start}° {angle_end}°")
|
shift = int(width/2)
|
||||||
self.x_pos = x_pos
|
self.x_pos = x_pos-shift
|
||||||
self.y_pos = y_pos
|
self.y_pos = y_pos-shift
|
||||||
self.width = width
|
self.width = width*2
|
||||||
self.angle_start = angle_start
|
self.angle_start = angle_start*16
|
||||||
self.angle_end = angle_end
|
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:
|
def paint(self, painter: QPainter, option: QStyleOptionGraphicsItem, widget: QWidget | None = ...) -> None:
|
||||||
shift = int(self.width/2)
|
painter.drawArc(self.x_pos, self.y_pos, self.width,
|
||||||
painter.drawArc(self.x_pos-shift, self.y_pos-shift, self.width*2,
|
self.width, self.angle_start, self.angle_end)
|
||||||
self.width*2, self.angle_start*16, self.angle_end*16)
|
|
||||||
|
|
||||||
def boundingRect(self) -> QRectF:
|
def boundingRect(self) -> QRectF:
|
||||||
return QRectF(0, 0, self.x_pos, self.y_pos)
|
return QRectF(0, 0, self.x_pos, self.y_pos)
|
||||||
@@ -5,12 +5,12 @@ from typing import List, Tuple
|
|||||||
from PySide6.QtWidgets import QGraphicsItemGroup
|
from PySide6.QtWidgets import QGraphicsItemGroup
|
||||||
from random import randint
|
from random import randint
|
||||||
|
|
||||||
from grid.ui.sphere_widget import SphereGraphicsItem, ArcGraphicsItem, LineGraphicsItem
|
from grid.ui.items import SphereGraphicsItem, ArcGraphicsItem, LineGraphicsItem
|
||||||
|
|
||||||
class Pattern(QGraphicsItemGroup):
|
class Pattern(QGraphicsItemGroup):
|
||||||
"""Common pattern on the sphere grid
|
"""Common pattern on the sphere grid
|
||||||
"""
|
"""
|
||||||
|
|
||||||
PATTERN_WIDTH = 250
|
PATTERN_WIDTH = 250
|
||||||
SPACE_BETWEEN_SPHERE = 60
|
SPACE_BETWEEN_SPHERE = 60
|
||||||
|
|
||||||
@@ -22,6 +22,7 @@ class Pattern(QGraphicsItemGroup):
|
|||||||
|
|
||||||
# center
|
# center
|
||||||
self.addToGroup(SphereGraphicsItem(center_x, center_y))
|
self.addToGroup(SphereGraphicsItem(center_x, center_y))
|
||||||
|
self.addToGroup(SphereGraphicsItem(0, 0))
|
||||||
|
|
||||||
# first cercle
|
# first cercle
|
||||||
sphere_on_circle = 4
|
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)
|
points = self.generate_circle_points(center_x, center_y, self.SPACE_BETWEEN_SPHERE*2, sphere_on_circle)
|
||||||
for x,y in points:
|
for x,y in points:
|
||||||
self.addToGroup(SphereGraphicsItem(x, y))
|
self.addToGroup(SphereGraphicsItem(x, y))
|
||||||
#for i in range(sphere_on_circle):
|
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, 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
|
# third cercle
|
||||||
sphere_on_circle = 8
|
sphere_on_circle = 8
|
||||||
|
|||||||
@@ -18,22 +18,16 @@ class Window(QWidget):
|
|||||||
self.setWindowTitle("sphere grid")
|
self.setWindowTitle("sphere grid")
|
||||||
self.setGeometry(0, 0, 600, 600)
|
self.setGeometry(0, 0, 600, 600)
|
||||||
|
|
||||||
self.scene = QGraphicsScene(0, 0, 600, 400)
|
self.scene = QGraphicsScene(0, 0, 600, 600)
|
||||||
|
|
||||||
pp = Pattern(200, 100)
|
pp = Pattern(300, 300)
|
||||||
#for wid in pp.content:
|
|
||||||
# self.scene.addItem(wid)
|
|
||||||
|
|
||||||
self.scene.addItem(pp)
|
self.scene.addItem(pp)
|
||||||
|
|
||||||
# Define our layout.
|
|
||||||
hbox = QHBoxLayout()
|
|
||||||
|
|
||||||
view = QGraphicsView(self.scene)
|
view = QGraphicsView(self.scene)
|
||||||
view.setRenderHint(QPainter.RenderHint.Antialiasing)
|
view.setRenderHint(QPainter.RenderHint.Antialiasing)
|
||||||
|
|
||||||
vbox = QHBoxLayout(self)
|
vbox = QHBoxLayout(self)
|
||||||
vbox.addLayout(hbox)
|
|
||||||
vbox.addWidget(view)
|
vbox.addWidget(view)
|
||||||
|
|
||||||
self.setLayout(vbox)
|
self.setLayout(vbox)
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
pyside6==6.6.1
|
pyside6==6.6.1
|
||||||
|
pytest==8.3.3
|
||||||
Reference in New Issue
Block a user