This commit is contained in:
Ian Jauslin 2024-02-22 17:19:52 -05:00
parent 1cd4e0fdc6
commit 121b8fe4b0
3 changed files with 37 additions and 3 deletions

View File

@ -20,7 +20,7 @@ import os.path
import filecheck import filecheck
import colors import colors
from polyomino import Cross,Disk,Staircase from polyomino import Cross,Disk,Staircase,Square2
class Command_prompt(Label): class Command_prompt(Label):
@ -390,6 +390,8 @@ class Command_prompt(Label):
self.app.painter.shape=Disk self.app.painter.shape=Disk
elif argv[2]=="staircase": elif argv[2]=="staircase":
self.app.painter.shape=Staircase self.app.painter.shape=Staircase
elif argv[2]=="2square":
self.app.painter.shape=Square2
else: else:
self.message="error: unrecognized shape '"+argv[2]+"'; supported shapes are cross|disk" self.message="error: unrecognized shape '"+argv[2]+"'; supported shapes are cross|disk"
return return

View File

@ -21,7 +21,7 @@ from kivy.core.window import Window
from kivy.graphics import Color,Line,Rectangle from kivy.graphics import Color,Line,Rectangle
from point import Point from point import Point
from polyomino import Cross,Disk,Staircase from polyomino import Cross,Disk,Staircase,Square2
from tools import remove_fromlist from tools import remove_fromlist
@ -542,6 +542,8 @@ class Painter(Widget):
ff.write("%shape=disk\n") ff.write("%shape=disk\n")
elif self.shape==Staircase: elif self.shape==Staircase:
ff.write("%shape=staircase\n") ff.write("%shape=staircase\n")
elif self.shape==Square2:
ff.write("%shape=2square\n")
else: else:
print("bug: unrecognized shape in write: '"+str(self.shape)+"'") print("bug: unrecognized shape in write: '"+str(self.shape)+"'")
ff.write("%zoom={:1.1f}\n".format(self.base_size/50)) ff.write("%zoom={:1.1f}\n".format(self.base_size/50))
@ -555,6 +557,8 @@ class Painter(Widget):
ff.write("{:d};".format(DISK_INDEX)) ff.write("{:d};".format(DISK_INDEX))
elif type(particle)==Staircase: elif type(particle)==Staircase:
ff.write("{:d};".format(STAIRCASE_INDEX)) ff.write("{:d};".format(STAIRCASE_INDEX))
elif type(particle)==Square2:
ff.write("{:d};".format(SQUARE2_INDEX))
ff.write("{:05.2f},{:05.2f};{:3.1f},{:3.1f},{:3.1f}\n".format(particle.elements[0].pos.x,particle.elements[0].pos.y,particle.color[0],particle.color[1],particle.color[2])) ff.write("{:05.2f},{:05.2f};{:3.1f},{:3.1f},{:3.1f}\n".format(particle.elements[0].pos.x,particle.elements[0].pos.y,particle.color[0],particle.color[1],particle.color[2]))
ff.close() ff.close()
@ -659,6 +663,8 @@ class Painter(Widget):
candidate=Disk(pos.x,pos.y,color=color) candidate=Disk(pos.x,pos.y,color=color)
elif particle_type==STAIRCASE_INDEX: elif particle_type==STAIRCASE_INDEX:
candidate=Staircase(pos.x,pos.y,color=color) candidate=Staircase(pos.x,pos.y,color=color)
elif particle_type==SQUARE2_INDEX:
candidate=Square2(pos.x,pos.y,color=color)
else: else:
print("warning: ignoring line "+str(i)+" in file '"+file+"': unrecognized particle type: '"+entries[0]+"'",file=sys.stderr) print("warning: ignoring line "+str(i)+" in file '"+file+"': unrecognized particle type: '"+entries[0]+"'",file=sys.stderr)
continue continue
@ -712,6 +718,7 @@ class Painter(Widget):
# global variables (used like precompiler variables) # global variables (used like precompiler variables)
CROSS_INDEX=1 CROSS_INDEX=1
DISK_INDEX=2 DISK_INDEX=2
STAIRCASE_INDEX=2 STAIRCASE_INDEX=3
SQUARE2_INDEX=4

View File

@ -152,3 +152,28 @@ class Staircase(Polyomino):
*(coordx-0.5*painter.base_size,coordy+1.5*painter.base_size), *(coordx-0.5*painter.base_size,coordy+1.5*painter.base_size),
*(coordx-0.5*painter.base_size,coordy-1.5*painter.base_size), *(coordx-0.5*painter.base_size,coordy-1.5*painter.base_size),
)) ))
# 2-square
class Square2(Polyomino):
def __init__(self,x,y,**kwargs):
super(Square2,self).__init__(**kwargs,elements=[\
Element_square(x,y,1),\
Element_square(x+1,y,1),\
Element_square(x,y+1,1),\
Element_square(x+1,y+1,1)\
])
# redefine stroke to avoid lines between touching elements
def stroke(self,painter):
# convert to graphical coordinates
coordx=painter.pos_tocoord_x(self.elements[0].pos.x)
coordy=painter.pos_tocoord_y(self.elements[0].pos.y)
Color(1,1,1)
Line(points=(
*(coordx-0.5*painter.base_size,coordy-0.5*painter.base_size),
*(coordx+1.5*painter.base_size,coordy-0.5*painter.base_size),
*(coordx+1.5*painter.base_size,coordy+1.5*painter.base_size),
*(coordx-0.5*painter.base_size,coordy+1.5*painter.base_size),
*(coordx-0.5*painter.base_size,coordy-0.5*painter.base_size),
))