added connected path shape to Life
This commit is contained in:
parent
9732f3bdeb
commit
8baa24e878
|
@ -133,13 +133,18 @@ class Component(Component):
|
||||||
|
|
||||||
def drawShape():
|
def drawShape():
|
||||||
drawer = ImageDraw.Draw(frame)
|
drawer = ImageDraw.Draw(frame)
|
||||||
|
rect = (
|
||||||
|
(drawPtX, drawPtY),
|
||||||
|
(drawPtX + self.pxWidth, drawPtY + self.pxHeight)
|
||||||
|
)
|
||||||
|
shape = self.page.comboBox_shapeType.currentText().lower()
|
||||||
|
|
||||||
# Rectangle
|
# Rectangle
|
||||||
if self.shapeType == 0:
|
if shape == 'rectangle':
|
||||||
drawer.rectangle(rect, fill=self.color)
|
drawer.rectangle(rect, fill=self.color)
|
||||||
|
|
||||||
# Ellipse
|
# Elliptical
|
||||||
elif self.shapeType == 1:
|
elif shape == 'elliptical':
|
||||||
drawer.ellipse(rect, fill=self.color)
|
drawer.ellipse(rect, fill=self.color)
|
||||||
|
|
||||||
tenthX, tenthY = scale(10, self.pxWidth, self.pxHeight, int)
|
tenthX, tenthY = scale(10, self.pxWidth, self.pxHeight, int)
|
||||||
|
@ -155,26 +160,75 @@ class Component(Component):
|
||||||
(drawPtX + self.pxWidth - int(tenthX / 4),
|
(drawPtX + self.pxWidth - int(tenthX / 4),
|
||||||
drawPtY + self.pxHeight - int(tenthY / 2))
|
drawPtY + self.pxHeight - int(tenthY / 2))
|
||||||
)
|
)
|
||||||
|
|
||||||
# Circle
|
# Circle
|
||||||
if self.shapeType == 2:
|
if shape == 'circle':
|
||||||
drawer.ellipse(outlineShape, fill=self.color)
|
drawer.ellipse(outlineShape, fill=self.color)
|
||||||
drawer.ellipse(smallerShape, fill=(0,0,0,0))
|
drawer.ellipse(smallerShape, fill=(0,0,0,0))
|
||||||
|
|
||||||
# Lilypad
|
# Lilypad
|
||||||
elif self.shapeType == 3:
|
elif shape == 'lilypad':
|
||||||
drawer.pieslice(smallerShape, 290, 250, fill=self.color)
|
drawer.pieslice(smallerShape, 290, 250, fill=self.color)
|
||||||
|
|
||||||
# Pac-Man
|
# Pac-Man
|
||||||
elif self.shapeType == 4:
|
elif shape == 'pac-man':
|
||||||
drawer.pieslice(outlineShape, 35, 320, fill=self.color)
|
drawer.pieslice(outlineShape, 35, 320, fill=self.color)
|
||||||
|
|
||||||
hX, hY = scale(50, self.pxWidth, self.pxHeight, int) # halfline
|
hX, hY = scale(50, self.pxWidth, self.pxHeight, int) # halfline
|
||||||
tX, tY = scale(33, self.pxWidth, self.pxHeight, int) # thirdline
|
tX, tY = scale(33, self.pxWidth, self.pxHeight, int) # thirdline
|
||||||
qX, qY = scale(20, self.pxWidth, self.pxHeight, int) # quarterline
|
qX, qY = scale(20, self.pxWidth, self.pxHeight, int) # quarterline
|
||||||
|
|
||||||
|
# Path
|
||||||
|
if shape == 'path':
|
||||||
|
drawer.ellipse(rect, fill=self.color)
|
||||||
|
rects = {
|
||||||
|
direction: False
|
||||||
|
for direction in (
|
||||||
|
'up', 'down', 'left', 'right',
|
||||||
|
)
|
||||||
|
}
|
||||||
|
for cell in nearbyCoords(x, y):
|
||||||
|
if grid.get(cell) is None:
|
||||||
|
continue
|
||||||
|
if cell[0] == x:
|
||||||
|
if cell[1] < y:
|
||||||
|
rects['up'] = True
|
||||||
|
if cell[1] > y:
|
||||||
|
rects['down'] = True
|
||||||
|
if cell[1] == y:
|
||||||
|
if cell[0] < x:
|
||||||
|
rects['left'] = True
|
||||||
|
if cell[0] > x:
|
||||||
|
rects['right'] = True
|
||||||
|
|
||||||
|
for direction, rect in rects.items():
|
||||||
|
if rect:
|
||||||
|
if direction == 'up':
|
||||||
|
sect = (
|
||||||
|
(drawPtX, drawPtY),
|
||||||
|
(drawPtX + self.pxWidth, drawPtY + hY)
|
||||||
|
)
|
||||||
|
elif direction == 'down':
|
||||||
|
sect = (
|
||||||
|
(drawPtX, drawPtY + hY),
|
||||||
|
(drawPtX + self.pxWidth,
|
||||||
|
drawPtY + self.pxHeight)
|
||||||
|
)
|
||||||
|
elif direction == 'left':
|
||||||
|
sect = (
|
||||||
|
(drawPtX, drawPtY),
|
||||||
|
(drawPtX + hX,
|
||||||
|
drawPtY + self.pxHeight)
|
||||||
|
)
|
||||||
|
elif direction == 'right':
|
||||||
|
sect = (
|
||||||
|
(drawPtX + hX, drawPtY),
|
||||||
|
(drawPtX + self.pxWidth,
|
||||||
|
drawPtY + self.pxHeight)
|
||||||
|
)
|
||||||
|
drawer.rectangle(sect, fill=self.color)
|
||||||
|
|
||||||
# Duck
|
# Duck
|
||||||
if self.shapeType == 5:
|
elif shape == 'duck':
|
||||||
duckHead = (
|
duckHead = (
|
||||||
(drawPtX + qX, drawPtY + qY),
|
(drawPtX + qX, drawPtY + qY),
|
||||||
(drawPtX + int(qX * 3), drawPtY + int(tY * 2))
|
(drawPtX + int(qX * 3), drawPtY + int(tY * 2))
|
||||||
|
@ -198,7 +252,7 @@ class Component(Component):
|
||||||
drawer.pieslice(duckBeak, 145, 200, fill=self.color)
|
drawer.pieslice(duckBeak, 145, 200, fill=self.color)
|
||||||
|
|
||||||
# Peace
|
# Peace
|
||||||
elif self.shapeType == 6:
|
elif shape == 'peace':
|
||||||
line = (
|
line = (
|
||||||
(drawPtX + hX - int(tenthX / 2), drawPtY + int(tenthY / 2)),
|
(drawPtX + hX - int(tenthX / 2), drawPtY + int(tenthY / 2)),
|
||||||
(drawPtX + hX + int(tenthX / 2),
|
(drawPtX + hX + int(tenthX / 2),
|
||||||
|
@ -231,10 +285,6 @@ class Component(Component):
|
||||||
drawPtY = y * self.pxHeight
|
drawPtY = y * self.pxHeight
|
||||||
if drawPtY > self.height:
|
if drawPtY > self.height:
|
||||||
continue
|
continue
|
||||||
rect = (
|
|
||||||
(drawPtX, drawPtY),
|
|
||||||
(drawPtX + self.pxWidth, drawPtY + self.pxHeight)
|
|
||||||
)
|
|
||||||
|
|
||||||
if self.customImg:
|
if self.customImg:
|
||||||
drawCustomImg()
|
drawCustomImg()
|
||||||
|
@ -253,23 +303,10 @@ class Component(Component):
|
||||||
'''Given a tick number over 0, returns a new grid dict of tuples'''
|
'''Given a tick number over 0, returns a new grid dict of tuples'''
|
||||||
lastGrid = self.tickGrids[tick - 1]
|
lastGrid = self.tickGrids[tick - 1]
|
||||||
|
|
||||||
def nearbyCoords(x, y):
|
|
||||||
yield x + 1, y + 1
|
|
||||||
yield x + 1, y - 1
|
|
||||||
yield x - 1, y + 1
|
|
||||||
yield x - 1, y - 1
|
|
||||||
yield x, y + 1
|
|
||||||
yield x, y - 1
|
|
||||||
yield x + 1, y
|
|
||||||
yield x - 1, y
|
|
||||||
|
|
||||||
def neighbours(x, y):
|
def neighbours(x, y):
|
||||||
nearbyCells = [
|
|
||||||
lastGrid.get(cell) for cell in nearbyCoords(x, y)
|
|
||||||
]
|
|
||||||
return [
|
return [
|
||||||
nearbyCell for nearbyCell in nearbyCells
|
cell for cell in nearbyCoords(x, y)
|
||||||
if nearbyCell is not None
|
if lastGrid.get(cell) is not None
|
||||||
]
|
]
|
||||||
|
|
||||||
newGrid = {}
|
newGrid = {}
|
||||||
|
@ -298,3 +335,14 @@ class Component(Component):
|
||||||
def loadPreset(self, pr, *args):
|
def loadPreset(self, pr, *args):
|
||||||
super().loadPreset(pr, *args)
|
super().loadPreset(pr, *args)
|
||||||
self.startingGrid = pr['GRID']
|
self.startingGrid = pr['GRID']
|
||||||
|
|
||||||
|
|
||||||
|
def nearbyCoords(x, y):
|
||||||
|
yield x + 1, y + 1
|
||||||
|
yield x + 1, y - 1
|
||||||
|
yield x - 1, y + 1
|
||||||
|
yield x - 1, y - 1
|
||||||
|
yield x, y + 1
|
||||||
|
yield x, y - 1
|
||||||
|
yield x + 1, y
|
||||||
|
yield x - 1, y
|
||||||
|
|
|
@ -213,6 +213,11 @@
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QComboBox" name="comboBox_shapeType">
|
<widget class="QComboBox" name="comboBox_shapeType">
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>Path</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Rectangle</string>
|
<string>Rectangle</string>
|
||||||
|
@ -220,7 +225,7 @@
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Ellipse</string>
|
<string>Elliptical</string>
|
||||||
</property>
|
</property>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
|
|
Reference in New Issue