This commit is contained in:
@@ -1,19 +0,0 @@
|
|||||||
name: Gitea Actions Demo
|
|
||||||
run-name: ${{ gitea.actor }} is testing out Gitea Actions 🚀
|
|
||||||
on: [push]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
Explore-Gitea-Actions:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- run: echo "🎉 The job was automatically triggered by a ${{ gitea.event_name }} event."
|
|
||||||
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by Gitea!"
|
|
||||||
- run: echo "🔎 The name of your branch is ${{ gitea.ref }} and your repository is ${{ gitea.repository }}."
|
|
||||||
- name: Check out repository code
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
- run: echo "💡 The ${{ gitea.repository }} repository has been cloned to the runner."
|
|
||||||
- run: echo "🖥️ The workflow is now ready to test your code on the runner."
|
|
||||||
- name: List files in the repository
|
|
||||||
run: |
|
|
||||||
ls ${{ gitea.workspace }}
|
|
||||||
- run: echo "🍏 This job's status is ${{ job.status }}."
|
|
||||||
23
.gitea/workflows/tests.yaml
Normal file
23
.gitea/workflows/tests.yaml
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
name: CI/CD
|
||||||
|
run-name: ${{ gitea.actor }} is testing out Gitea Actions 🚀
|
||||||
|
|
||||||
|
on: [push]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- name: Set up Python
|
||||||
|
uses: actions/setup-python@v5
|
||||||
|
with:
|
||||||
|
python-version: '3.12'
|
||||||
|
cache: 'pip'
|
||||||
|
- run: pip install -r requirements.txt
|
||||||
|
- name: Install the code linting and formatting tool Ruff
|
||||||
|
run: pip install ruff
|
||||||
|
- name: Lint code with Ruff
|
||||||
|
run: ruff check --output-format=github --target-version=py39
|
||||||
|
- name: Check code formatting with Ruff
|
||||||
|
run: ruff format --diff --target-version=py39
|
||||||
|
continue-on-error: true
|
||||||
@@ -1,22 +1,21 @@
|
|||||||
class Cell:
|
class Cell:
|
||||||
|
|
||||||
MIN_NEIGHBORS = 1
|
MIN_NEIGHBORS = 1
|
||||||
MAX_NEIGHBORS = 4
|
MAX_NEIGHBORS = 4
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self.neighbors = []
|
self.neighbors = []
|
||||||
|
|
||||||
def add_neightbor(self, new_neighbor: 'Cell'):
|
def add_neightbor(self, new_neighbor: "Cell"):
|
||||||
self.neighbors.append(new_neighbor)
|
self.neighbors.append(new_neighbor)
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
return "o"
|
return "o"
|
||||||
|
|
||||||
class StatSphere(Cell):
|
|
||||||
|
|
||||||
|
class StatSphere(Cell):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class StrengthSphere(StatSphere):
|
|
||||||
|
|
||||||
|
class StrengthSphere(StatSphere):
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
"""
|
""" """
|
||||||
"""
|
|
||||||
from random import choice, randint
|
from random import choice, randint
|
||||||
|
|
||||||
from grid.sphere.cell import Cell
|
from grid.sphere.cell import Cell
|
||||||
|
|
||||||
class Grid:
|
|
||||||
|
|
||||||
|
class Grid:
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self.start = None
|
self.start = None
|
||||||
|
|
||||||
@@ -13,7 +13,7 @@ class Grid:
|
|||||||
self.start = cell
|
self.start = cell
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def generate_grid(cls, sphere_number: int=10) -> 'Grid':
|
def generate_grid(cls, sphere_number: int = 10) -> "Grid":
|
||||||
# pick an impl type instead
|
# pick an impl type instead
|
||||||
starting_point = Cell()
|
starting_point = Cell()
|
||||||
cls.generate_neighbors(starting_point, sphere_number)
|
cls.generate_neighbors(starting_point, sphere_number)
|
||||||
@@ -26,5 +26,5 @@ class Grid:
|
|||||||
number_of_neighbor = randint(Cell.MIN_NEIGHBORS, Cell.MAX_NEIGHBORS)
|
number_of_neighbor = randint(Cell.MIN_NEIGHBORS, Cell.MAX_NEIGHBORS)
|
||||||
for _ in number_of_neighbor:
|
for _ in number_of_neighbor:
|
||||||
current_cell.add_neightbor(Cell())
|
current_cell.add_neightbor(Cell())
|
||||||
remaining_cells = max(0, remaining_cells-number_of_neighbor)
|
remaining_cells = max(0, remaining_cells - number_of_neighbor)
|
||||||
return choice(current_cell.neighbors)
|
return choice(current_cell.neighbors)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
from grid.ui.pattern import Pattern
|
from grid.ui.pattern import Pattern
|
||||||
|
|
||||||
class TestPattern():
|
|
||||||
|
|
||||||
|
class TestPattern:
|
||||||
def test_position(self):
|
def test_position(self):
|
||||||
p = Pattern(500, 500)
|
p = Pattern(500, 500)
|
||||||
assert len(p.childItems()) > 0
|
assert len(p.childItems()) > 0
|
||||||
@@ -1,13 +1,23 @@
|
|||||||
from PySide6.QtCore import QRectF, Qt
|
from PySide6.QtCore import QRectF, Qt
|
||||||
from PySide6.QtGui import QBrush, QPainter, QPen
|
from PySide6.QtGui import QBrush, QPainter, QPen
|
||||||
from PySide6.QtWidgets import QGraphicsEllipseItem, QGraphicsItem, QStyleOptionGraphicsItem, QWidget
|
from PySide6.QtWidgets import (
|
||||||
|
QGraphicsEllipseItem,
|
||||||
|
QGraphicsItem,
|
||||||
|
QStyleOptionGraphicsItem,
|
||||||
|
QWidget,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class SphereGraphicsItem(QGraphicsEllipseItem):
|
class SphereGraphicsItem(QGraphicsEllipseItem):
|
||||||
|
|
||||||
SPHERE_WIDTH = 30
|
SPHERE_WIDTH = 30
|
||||||
|
|
||||||
def __init__(self, x_pos: int, y_pos: int) -> None:
|
def __init__(self, x_pos: int, y_pos: int) -> None:
|
||||||
super().__init__(self.SPHERE_WIDTH/2, self.SPHERE_WIDTH/2, self.SPHERE_WIDTH, self.SPHERE_WIDTH)
|
super().__init__(
|
||||||
|
self.SPHERE_WIDTH / 2,
|
||||||
|
self.SPHERE_WIDTH / 2,
|
||||||
|
self.SPHERE_WIDTH,
|
||||||
|
self.SPHERE_WIDTH,
|
||||||
|
)
|
||||||
print(f"sphere at {x_pos}:{y_pos}")
|
print(f"sphere at {x_pos}:{y_pos}")
|
||||||
self.setPos(x_pos, y_pos)
|
self.setPos(x_pos, y_pos)
|
||||||
brush = QBrush(Qt.GlobalColor.darkBlue)
|
brush = QBrush(Qt.GlobalColor.darkBlue)
|
||||||
@@ -17,28 +27,56 @@ class SphereGraphicsItem(QGraphicsEllipseItem):
|
|||||||
self.setPen(pen)
|
self.setPen(pen)
|
||||||
self.show()
|
self.show()
|
||||||
|
|
||||||
|
|
||||||
class ArcGraphicsItem(QGraphicsItem):
|
class ArcGraphicsItem(QGraphicsItem):
|
||||||
|
def __init__(
|
||||||
def __init__(self, x_pos: int, y_pos: int, width: int, angle_start: int, angle_end: int, parent: QGraphicsItem | None = ...):
|
self,
|
||||||
|
x_pos: int,
|
||||||
|
y_pos: int,
|
||||||
|
width: int,
|
||||||
|
angle_start: int,
|
||||||
|
angle_end: int,
|
||||||
|
parent: QGraphicsItem | None = ...,
|
||||||
|
):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
shift = int(width/2)
|
shift = int(width / 2)
|
||||||
self.x_pos = x_pos-shift
|
self.x_pos = x_pos - shift
|
||||||
self.y_pos = y_pos-shift
|
self.y_pos = y_pos - shift
|
||||||
self.width = width*2
|
self.width = width * 2
|
||||||
self.angle_start = angle_start*16
|
self.angle_start = angle_start * 16
|
||||||
self.angle_end = angle_end*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}°")
|
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(
|
||||||
painter.drawArc(self.x_pos, self.y_pos, self.width,
|
self,
|
||||||
self.width, self.angle_start, self.angle_end)
|
painter: QPainter,
|
||||||
|
option: QStyleOptionGraphicsItem,
|
||||||
|
widget: QWidget | None = ...,
|
||||||
|
) -> None:
|
||||||
|
painter.drawArc(
|
||||||
|
self.x_pos,
|
||||||
|
self.y_pos,
|
||||||
|
self.width,
|
||||||
|
self.width,
|
||||||
|
self.angle_start,
|
||||||
|
self.angle_end,
|
||||||
|
)
|
||||||
|
|
||||||
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)
|
||||||
|
|
||||||
class LineGraphicsItem(QGraphicsItem):
|
|
||||||
|
|
||||||
def __init__(self, begin_x: int, begin_y: int, end_x: int, end_y: int, parent: QGraphicsItem | None = ...) -> None:
|
class LineGraphicsItem(QGraphicsItem):
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
begin_x: int,
|
||||||
|
begin_y: int,
|
||||||
|
end_x: int,
|
||||||
|
end_y: int,
|
||||||
|
parent: QGraphicsItem | None = ...,
|
||||||
|
) -> None:
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
print(f"line from {begin_x}:{begin_y} to {end_x}:{end_y}")
|
print(f"line from {begin_x}:{begin_y} to {end_x}:{end_y}")
|
||||||
self.begin_x = begin_x
|
self.begin_x = begin_x
|
||||||
@@ -46,7 +84,12 @@ class LineGraphicsItem(QGraphicsItem):
|
|||||||
self.end_x = end_x
|
self.end_x = end_x
|
||||||
self.end_y = end_y
|
self.end_y = end_y
|
||||||
|
|
||||||
def paint(self, painter: QPainter, option: QStyleOptionGraphicsItem, widget: QWidget | None = ...) -> None:
|
def paint(
|
||||||
|
self,
|
||||||
|
painter: QPainter,
|
||||||
|
option: QStyleOptionGraphicsItem,
|
||||||
|
widget: QWidget | None = ...,
|
||||||
|
) -> None:
|
||||||
painter.drawLine(self.begin_x, self.begin_y, self.end_x, self.end_y)
|
painter.drawLine(self.begin_x, self.begin_y, self.end_x, self.end_y)
|
||||||
|
|
||||||
def boundingRect(self) -> QRectF:
|
def boundingRect(self) -> QRectF:
|
||||||
|
|||||||
@@ -85,21 +85,19 @@ class TrafficLight(QWidget):
|
|||||||
|
|
||||||
machine = QStateMachine(self)
|
machine = QStateMachine(self)
|
||||||
red_going_yellow = create_light_state(widget._red_light, 1000)
|
red_going_yellow = create_light_state(widget._red_light, 1000)
|
||||||
red_going_yellow.setObjectName('redGoingYellow')
|
red_going_yellow.setObjectName("redGoingYellow")
|
||||||
yellow_going_green = create_light_state(widget._red_light, 1000)
|
yellow_going_green = create_light_state(widget._red_light, 1000)
|
||||||
yellow_going_green.setObjectName('yellowGoingGreen')
|
yellow_going_green.setObjectName("yellowGoingGreen")
|
||||||
red_going_yellow.addTransition(red_going_yellow.finished,
|
red_going_yellow.addTransition(red_going_yellow.finished, yellow_going_green)
|
||||||
yellow_going_green)
|
|
||||||
green_going_yellow = create_light_state(widget._yellow_light, 3000)
|
green_going_yellow = create_light_state(widget._yellow_light, 3000)
|
||||||
green_going_yellow.setObjectName('greenGoingYellow')
|
green_going_yellow.setObjectName("greenGoingYellow")
|
||||||
yellow_going_green.addTransition(yellow_going_green.finished,
|
yellow_going_green.addTransition(
|
||||||
green_going_yellow)
|
yellow_going_green.finished, green_going_yellow
|
||||||
|
)
|
||||||
yellow_going_red = create_light_state(widget._green_light, 1000)
|
yellow_going_red = create_light_state(widget._green_light, 1000)
|
||||||
yellow_going_red.setObjectName('yellowGoingRed')
|
yellow_going_red.setObjectName("yellowGoingRed")
|
||||||
green_going_yellow.addTransition(green_going_yellow.finished,
|
green_going_yellow.addTransition(green_going_yellow.finished, yellow_going_red)
|
||||||
yellow_going_red)
|
yellow_going_red.addTransition(yellow_going_red.finished, red_going_yellow)
|
||||||
yellow_going_red.addTransition(yellow_going_red.finished,
|
|
||||||
red_going_yellow)
|
|
||||||
|
|
||||||
machine.addState(red_going_yellow)
|
machine.addState(red_going_yellow)
|
||||||
machine.addState(yellow_going_green)
|
machine.addState(yellow_going_green)
|
||||||
@@ -109,7 +107,7 @@ class TrafficLight(QWidget):
|
|||||||
machine.start()
|
machine.start()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == "__main__":
|
||||||
app = QApplication(sys.argv)
|
app = QApplication(sys.argv)
|
||||||
widget = TrafficLight()
|
widget = TrafficLight()
|
||||||
widget.resize(110, 300)
|
widget.resize(110, 300)
|
||||||
|
|||||||
@@ -3,13 +3,12 @@ import math
|
|||||||
from typing import List, Tuple
|
from typing import List, Tuple
|
||||||
|
|
||||||
from PySide6.QtWidgets import QGraphicsItemGroup
|
from PySide6.QtWidgets import QGraphicsItemGroup
|
||||||
from random import randint
|
|
||||||
|
|
||||||
from grid.ui.items 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
|
||||||
@@ -26,35 +25,66 @@ class Pattern(QGraphicsItemGroup):
|
|||||||
|
|
||||||
# first cercle
|
# first cercle
|
||||||
sphere_on_circle = 4
|
sphere_on_circle = 4
|
||||||
points = self.generate_circle_points(center_x, center_y, self.SPACE_BETWEEN_SPHERE, sphere_on_circle)
|
points = self.generate_circle_points(
|
||||||
for x,y in points:
|
center_x, center_y, self.SPACE_BETWEEN_SPHERE, sphere_on_circle
|
||||||
|
)
|
||||||
|
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, (i*360/sphere_on_circle)%360, ((i+1)*360/sphere_on_circle)%360, self))
|
self.addToGroup(
|
||||||
|
ArcGraphicsItem(
|
||||||
|
center_x,
|
||||||
|
center_y,
|
||||||
|
self.SPACE_BETWEEN_SPHERE,
|
||||||
|
(i * 360 / sphere_on_circle) % 360,
|
||||||
|
((i + 1) * 360 / sphere_on_circle) % 360,
|
||||||
|
self,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
line_start_x = int(center_x + self.SPACE_BETWEEN_SPHERE / 2)
|
||||||
line_start_x = int(center_x + self.SPACE_BETWEEN_SPHERE/2)
|
line_start_y = int(center_y + self.SPACE_BETWEEN_SPHERE / 2)
|
||||||
line_start_y = int(center_y + self.SPACE_BETWEEN_SPHERE/2)
|
line_end_x = int(center_x + self.SPACE_BETWEEN_SPHERE / 2)
|
||||||
line_end_x = int(center_x + self.SPACE_BETWEEN_SPHERE/2)
|
line_end_y = int(center_y + self.SPACE_BETWEEN_SPHERE * 1.5)
|
||||||
line_end_y = int(center_y + self.SPACE_BETWEEN_SPHERE*1.5)
|
self.addToGroup(
|
||||||
self.addToGroup(LineGraphicsItem(line_start_x, line_start_y, line_end_x, line_end_y, self))
|
LineGraphicsItem(line_start_x, line_start_y, line_end_x, line_end_y, self)
|
||||||
|
)
|
||||||
|
|
||||||
# second cercle
|
# second cercle
|
||||||
sphere_on_circle = 8
|
sphere_on_circle = 8
|
||||||
points = self.generate_circle_points(center_x, center_y, self.SPACE_BETWEEN_SPHERE*2, sphere_on_circle)
|
points = self.generate_circle_points(
|
||||||
for x,y in points:
|
center_x, center_y, self.SPACE_BETWEEN_SPHERE * 2, sphere_on_circle
|
||||||
|
)
|
||||||
|
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(
|
||||||
self.addToGroup(ArcGraphicsItem(center_x, center_y, self.SPACE_BETWEEN_SPHERE*2, 0, 90, self))
|
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
|
||||||
points = self.generate_circle_points(center_x, center_y, self.SPACE_BETWEEN_SPHERE*3, sphere_on_circle)
|
points = self.generate_circle_points(
|
||||||
for x,y in points:
|
center_x, center_y, self.SPACE_BETWEEN_SPHERE * 3, sphere_on_circle
|
||||||
|
)
|
||||||
|
for x, y in points:
|
||||||
self.addToGroup(SphereGraphicsItem(x, y))
|
self.addToGroup(SphereGraphicsItem(x, y))
|
||||||
|
|
||||||
def generate_circle_points(self, center_x: int, center_y: int, radius: int, n_points: int) -> List[Tuple[int, int]]:
|
def generate_circle_points(
|
||||||
|
self, center_x: int, center_y: int, radius: int, n_points: int
|
||||||
|
) -> List[Tuple[int, int]]:
|
||||||
"""generate coordinates of points on a circle equally spaced
|
"""generate coordinates of points on a circle equally spaced
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
|||||||
@@ -6,13 +6,13 @@ from PySide6.QtWidgets import (
|
|||||||
QGraphicsScene,
|
QGraphicsScene,
|
||||||
QGraphicsView,
|
QGraphicsView,
|
||||||
QHBoxLayout,
|
QHBoxLayout,
|
||||||
QWidget
|
QWidget,
|
||||||
)
|
)
|
||||||
|
|
||||||
from grid.ui.pattern import Pattern
|
from grid.ui.pattern import Pattern
|
||||||
|
|
||||||
class Window(QWidget):
|
|
||||||
|
|
||||||
|
class Window(QWidget):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.setWindowTitle("sphere grid")
|
self.setWindowTitle("sphere grid")
|
||||||
@@ -21,7 +21,6 @@ class Window(QWidget):
|
|||||||
self.scene = QGraphicsScene(0, 0, 600, 600)
|
self.scene = QGraphicsScene(0, 0, 600, 600)
|
||||||
|
|
||||||
pp = Pattern(300, 300)
|
pp = Pattern(300, 300)
|
||||||
|
|
||||||
self.scene.addItem(pp)
|
self.scene.addItem(pp)
|
||||||
|
|
||||||
view = QGraphicsView(self.scene)
|
view = QGraphicsView(self.scene)
|
||||||
@@ -33,6 +32,7 @@ class Window(QWidget):
|
|||||||
self.setLayout(vbox)
|
self.setLayout(vbox)
|
||||||
self.show()
|
self.show()
|
||||||
|
|
||||||
|
|
||||||
app = QApplication(sys.argv)
|
app = QApplication(sys.argv)
|
||||||
w = Window()
|
w = Window()
|
||||||
app.exec()
|
app.exec()
|
||||||
|
|||||||
Reference in New Issue
Block a user