[MOD] alignment is messed up
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1,3 @@
|
||||
.vscode/
|
||||
__pycache__
|
||||
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
|
||||
|
||||
- [ ] seeded RNG
|
||||
- [ ] pattern: circle, line
|
||||
- [ ] pattern: classic circles, line to connect far away patterns
|
||||
- [ ] path finding
|
||||
|
||||
# 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 = ...):
|
||||
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)
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
pyside6==6.6.1
|
||||
pytest==8.3.3
|
||||
Reference in New Issue
Block a user