From cf806828901c429f6de9298bc07a3805ee8d4bb0 Mon Sep 17 00:00:00 2001 From: Ian Jauslin Date: Wed, 24 Nov 2021 22:46:47 -0500 Subject: [PATCH] Crosses --- painter.py | 4 ++-- polyomino.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/painter.py b/painter.py index 8db1e89..4950aab 100644 --- a/painter.py +++ b/painter.py @@ -4,7 +4,7 @@ from kivy.uix.widget import Widget from kivy.core.window import Window from point import Point -from polyomino import Square +from polyomino import Cross from polyomino import Square_element from tools import remove_fromlist @@ -81,7 +81,7 @@ class Painter(Widget): # create new cross if touch.button=="right": - new=Square(touch.x/Square_element.size,touch.y/Square_element.size) + new=Cross(touch.x/Square_element.size,touch.y/Square_element.size) if not self.check_interaction_any(new,Point(0,0)): # add to list self.particles.append(new) diff --git a/polyomino.py b/polyomino.py index 88996ae..a255856 100644 --- a/polyomino.py +++ b/polyomino.py @@ -68,6 +68,36 @@ class Square(Polyomino): def __init__(self,x,y,**kwargs): super(Square,self).__init__(**kwargs,squares=[Square_element(x,y)]) +# cross +class Cross(Polyomino): + def __init__(self,x,y,**kwargs): + super(Cross,self).__init__(**kwargs,squares=[\ + Square_element(x,y),\ + Square_element(x+1,y),\ + Square_element(x-1,y),\ + Square_element(x,y+1),\ + Square_element(x,y-1)\ + ]) + + # redefine stroke to avoid lines between touching squares + def stroke(self): + Color(1,1,1) + Line(points=( + *((self.squares[0].pos.x-0.5)*Square_element.size,(self.squares[0].pos.y-0.5)*Square_element.size), + *((self.squares[0].pos.x-0.5)*Square_element.size,(self.squares[0].pos.y-1.5)*Square_element.size), + *((self.squares[0].pos.x+0.5)*Square_element.size,(self.squares[0].pos.y-1.5)*Square_element.size), + *((self.squares[0].pos.x+0.5)*Square_element.size,(self.squares[0].pos.y-0.5)*Square_element.size), + *((self.squares[0].pos.x+1.5)*Square_element.size,(self.squares[0].pos.y-0.5)*Square_element.size), + *((self.squares[0].pos.x+1.5)*Square_element.size,(self.squares[0].pos.y+0.5)*Square_element.size), + *((self.squares[0].pos.x+0.5)*Square_element.size,(self.squares[0].pos.y+0.5)*Square_element.size), + *((self.squares[0].pos.x+0.5)*Square_element.size,(self.squares[0].pos.y+1.5)*Square_element.size), + *((self.squares[0].pos.x-0.5)*Square_element.size,(self.squares[0].pos.y+1.5)*Square_element.size), + *((self.squares[0].pos.x-0.5)*Square_element.size,(self.squares[0].pos.y+0.5)*Square_element.size), + *((self.squares[0].pos.x-1.5)*Square_element.size,(self.squares[0].pos.y+0.5)*Square_element.size), + *((self.squares[0].pos.x-1.5)*Square_element.size,(self.squares[0].pos.y-0.5)*Square_element.size), + *((self.squares[0].pos.x-0.5)*Square_element.size,(self.squares[0].pos.y-0.5)*Square_element.size), + )) + # square building block of polyominos