Compare commits

...

10 Commits

11 changed files with 409 additions and 64 deletions

16
TeX/jam.sty Normal file
View File

@@ -0,0 +1,16 @@
% square lattice (width #1, height #2, origin #3, spacing #4)
\def\grid#1#2#3{
\foreach\i in {0,...,#2}{
\draw#3++(0,\i)--++(#1,0);
}
\foreach\i in {0,...,#1}{
\draw#3++(\i,0)--++(0,#2);
}
}
% cross (color #1, position #2)
\def\cross#1#2{
\fill[color=#1]#2++(0.5,0.5)--++(0,1)--++(-1,0)--++(0,-1)--++(-1,0)--++(0,-1)--++(1,0)--++(0,-1)--++(1,0)--++(0,1)--++(1,0)--++(0,1)--++(-1,0);
\draw[color=black]#2++(0.5,0.5)--++(0,1)--++(-1,0)--++(0,-1)--++(-1,0)--++(0,-1)--++(1,0)--++(0,-1)--++(1,0)--++(0,1)--++(1,0)--++(0,1)--++(-1,0);
}

188
src/colors.py Normal file
View File

@@ -0,0 +1,188 @@
# find named color that is closest to rgb values
def closest_color(rgb,names):
name=""
mindist=float('inf')
for color in names:
dist=(rgb[0]-color[1])**2+(rgb[1]-color[2])**2+(rgb[2]-color[3])**2
if dist<mindist:
name=color[0]
mindist=dist
return name
# color names
## This is adapted from the LaTeX xcolor package
## which is licensed under the LaTeX Project Public License v1.3c
## by Dr. Uwe Kern
##
xcolor_names=[#
["red",1,0,0],#
["green",0,1,0],#
["blue",0,0,1],#
["brown",.75,.5,.25],#
["lime",.75,1,0],#
["orange",1,.5,0],#
["pink",1,.75,.75],#
["purple",.75,0,.25],#
["teal",0,.5,.5],#
["violet",.5,0,.5],#
["cyan",0,1,1],#
["magenta",1,0,1],#
["yellow",1,1,0],#
["olive",.5,.5,0],#
["black",0,0,0],#
["darkgray",.25,.25,.25],#
["gray",.5,.5,.5],#
["lightgray",.75,.75,.75],#
["white",1,1,1],#
##
["AliceBlue",.94,.972,1],#
["AntiqueWhite",.98,.92,.844],#
["Aquamarine",.498,1,.83],#
["Azure",.94,1,1],#
["Beige",.96,.96,.864],#
["Bisque",1,.894,.77],#
["Black",0,0,0],#
["BlanchedAlmond",1,.92,.804],#
["Blue",0,0,1],#
["BlueViolet",.54,.17,.888],#
["Brown",.648,.165,.165],#
["BurlyWood",.87,.72,.53],#
["CadetBlue",.372,.62,.628],#
["Chartreuse",.498,1,0],#
["Chocolate",.824,.41,.116],#
["Coral",1,.498,.312],#
["CornflowerBlue",.392,.585,.93],#
["Cornsilk",1,.972,.864],#
["Crimson",.864,.08,.235],#
["Cyan",0,1,1],#
["DarkBlue",0,0,.545],#
["DarkCyan",0,.545,.545],#
["DarkGoldenrod",.72,.525,.044],#
["DarkGray",.664,.664,.664],#
["DarkGreen",0,.392,0],#
["DarkGrey",.664,.664,.664],#
["DarkKhaki",.74,.716,.42],#
["DarkMagenta",.545,0,.545],#
["DarkOliveGreen",.332,.42,.185],#
["DarkOrange",1,.55,0],#
["DarkOrchid",.6,.196,.8],#
["DarkRed",.545,0,0],#
["DarkSalmon",.912,.59,.48],#
["DarkSeaGreen",.56,.736,.56],#
["DarkSlateBlue",.284,.24,.545],#
["DarkSlateGray",.185,.31,.31],#
["DarkSlateGrey",.185,.31,.31],#
["DarkTurquoise",0,.808,.82],#
["DarkViolet",.58,0,.828],#
["DeepPink",1,.08,.576],#
["DeepSkyBlue",0,.75,1],#
["DimGray",.41,.41,.41],#
["DimGrey",.41,.41,.41],#
["DodgerBlue",.116,.565,1],#
["FireBrick",.698,.132,.132],#
["FloralWhite",1,.98,.94],#
["ForestGreen",.132,.545,.132],#
["Gainsboro",.864,.864,.864],#
["GhostWhite",.972,.972,1],#
["Gold",1,.844,0],#
["Goldenrod",.855,.648,.125],#
["Gray",.5,.5,.5],#
["Green",0,.5,0],#
["GreenYellow",.68,1,.185],#
["Grey",.5,.5,.5],#
["Honeydew",.94,1,.94],#
["HotPink",1,.41,.705],#
["IndianRed",.804,.36,.36],#
["Indigo",.294,0,.51],#
["Ivory",1,1,.94],#
["Khaki",.94,.9,.55],#
["Lavender",.9,.9,.98],#
["LavenderBlush",1,.94,.96],#
["LawnGreen",.488,.99,0],#
["LemonChiffon",1,.98,.804],#
["LightBlue",.68,.848,.9],#
["LightCoral",.94,.5,.5],#
["LightCyan",.88,1,1],#
["LightGoldenrod",.933,.867,.51],#
["LightGoldenrodYellow",.98,.98,.824],#
["LightGray",.828,.828,.828],#
["LightGreen",.565,.932,.565],#
["LightGrey",.828,.828,.828],#
["LightPink",1,.712,.756],#
["LightSalmon",1,.628,.48],#
["LightSeaGreen",.125,.698,.668],#
["LightSkyBlue",.53,.808,.98],#
["LightSlateBlue",.518,.44,1],#
["LightSlateGray",.468,.532,.6],#
["LightSlateGrey",.468,.532,.6],#
["LightSteelBlue",.69,.77,.87],#
["LightYellow",1,1,.88],#
["Lime",0,1,0],#
["LimeGreen",.196,.804,.196],#
["Linen",.98,.94,.9],#
["Magenta",1,0,1],#
["Maroon",.5,0,0],#
["MediumAquamarine",.4,.804,.668],#
["MediumBlue",0,0,.804],#
["MediumOrchid",.73,.332,.828],#
["MediumPurple",.576,.44,.86],#
["MediumSeaGreen",.235,.7,.444],#
["MediumSlateBlue",.484,.408,.932],#
["MediumSpringGreen",0,.98,.604],#
["MediumTurquoise",.284,.82,.8],#
["MediumVioletRed",.78,.084,.52],#
["MidnightBlue",.098,.098,.44],#
["MintCream",.96,1,.98],#
["MistyRose",1,.894,.884],#
["Moccasin",1,.894,.71],#
["NavajoWhite",1,.87,.68],#
["Navy",0,0,.5],#
["NavyBlue",0,0,.5],#
["OldLace",.992,.96,.9],#
["Olive",.5,.5,0],#
["OliveDrab",.42,.556,.136],#
["Orange",1,.648,0],#
["OrangeRed",1,.27,0],#
["Orchid",.855,.44,.84],#
["PaleGoldenrod",.932,.91,.668],#
["PaleGreen",.596,.985,.596],#
["PaleTurquoise",.688,.932,.932],#
["PaleVioletRed",.86,.44,.576],#
["PapayaWhip",1,.936,.835],#
["PeachPuff",1,.855,.725],#
["Peru",.804,.52,.248],#
["Pink",1,.752,.796],#
["Plum",.868,.628,.868],#
["PowderBlue",.69,.88,.9],#
["Purple",.5,0,.5],#
["Red",1,0,0],#
["RosyBrown",.736,.56,.56],#
["RoyalBlue",.255,.41,.884],#
["SaddleBrown",.545,.27,.075],#
["Salmon",.98,.5,.448],#
["SandyBrown",.956,.644,.376],#
["SeaGreen",.18,.545,.34],#
["Seashell",1,.96,.932],#
["Sienna",.628,.32,.176],#
["Silver",.752,.752,.752],#
["SkyBlue",.53,.808,.92],#
["SlateBlue",.415,.352,.804],#
["SlateGray",.44,.5,.565],#
["SlateGrey",.44,.5,.565],#
["Snow",1,.98,.98],#
["SpringGreen",0,1,.498],#
["SteelBlue",.275,.51,.705],#
["Tan",.824,.705,.55],#
["Teal",0,.5,.5],#
["Thistle",.848,.75,.848],#
["Tomato",1,.39,.28],#
["Turquoise",.25,.88,.815],#
["Violet",.932,.51,.932],#
["VioletRed",.816,.125,.565],#
["Wheat",.96,.87,.7],#
["White",1,1,1],#
["WhiteSmoke",.96,.96,.96],#
["Yellow",1,1,0],#
["YellowGreen",.604,.804,.196]#
]

View File

@@ -5,6 +5,7 @@ import glob
import os.path import os.path
import filecheck import filecheck
import colors
class Command_prompt(Label): class Command_prompt(Label):
@@ -259,7 +260,7 @@ class Command_prompt(Label):
cursor=self.parse_argv() cursor=self.parse_argv()
# write and edit commands # write and edit commands
if self.argv[0]=="w" or self.argv[0]=="e": if self.argv[0]=="w" or self.argv[0]=="e" or self.argv[0]=="export":
# check that cursor is in first argument # check that cursor is in first argument
if cursor[0]==1: if cursor[0]==1:
# complete filesystem path # complete filesystem path
@@ -307,6 +308,9 @@ class Command_prompt(Label):
# edit file # edit file
if self.argv[0]=="e": if self.argv[0]=="e":
self.run_edit(self.argv) self.run_edit(self.argv)
# export to file
if self.argv[0]=="export":
self.run_export(self.argv)
# quit # quit
if self.argv[0]=="q" or self.argv=="wq": if self.argv[0]=="q" or self.argv=="wq":
self.app.stop() self.app.stop()
@@ -323,6 +327,8 @@ class Command_prompt(Label):
elif argv[1]=="grid": elif argv[1]=="grid":
self.run_set_grid(argv) self.run_set_grid(argv)
return return
elif argv[1]=="zoom":
self.run_set_zoom(argv)
else: else:
self.message="error: unrecognized command '"+argv[1]+"'" self.message="error: unrecognized command '"+argv[1]+"'"
return return
@@ -332,34 +338,23 @@ class Command_prompt(Label):
if len(argv)<3: if len(argv)<3:
self.message="error: 'set color' command was run with without anargument -- usage: 'set color <color_descriptor>'" self.message="error: 'set color' command was run with without anargument -- usage: 'set color <color_descriptor>'"
return return
if argv[2]=="blue": # find color name in list
self.app.painter.set_color((0,0,1)) for color in colors.xcolor_names:
elif argv[2]=="green": if argv[2]==color[0]:
self.app.painter.set_color((0,1,0)) self.app.painter.set_color(color[1:])
elif argv[2]=="red": return
self.app.painter.set_color((1,0,0))
elif argv[2]=="cyan": # numerical rgb values
self.app.painter.set_color((0,1,1))
elif argv[2]=="magenta":
self.app.painter.set_color((1,0,1))
elif argv[2]=="yellow":
self.app.painter.set_color((1,1,0))
elif argv[2]=="white":
self.app.painter.set_color((1,1,1))
elif argv[2]=="black":
self.app.painter.set_color((0,0,0))
elif argv[2]=="gray":
self.app.painter.set_color((0.5,0.5,0.5))
else:
color_str=argv[2].split(",") color_str=argv[2].split(",")
# error if improperly formatted # error if improperly formatted
if len(color_str)!=3: if len(color_str)!=3:
self.message="error: unrecognized color specification '"+argv[2]+"'; supported format is 'r,g,b' or one of red|green|blue|cyan|magenta|yellow|white|black|gray" self.message="error: unrecognized color specification '"+argv[2]+"'; supported format is 'r,g,b' or one of red|green|blue|brown|lime|orange|pink|purple|teal|violet|cyan|magenta|yellow|olive|black|darkgray|gray|lightgray|white or an SVG color name"
return return
try: try:
color=(float(color_str[0]),float(color_str[1]),float(color_str[2])) color=(float(color_str[0]),float(color_str[1]),float(color_str[2]))
except: except:
self.message="error: unrecognized color specification '"+argv[2]+"'; supported format is 'r,g,b' or one of red|green|blue|cyan|magenta|yellow|white|black|gray" self.message="error: unrecognized color specification '"+argv[2]+"'; supported format is 'r,g,b' or one of red|green|blue|brown|lime|orange|pink|purple|teal|violet|cyan|magenta|yellow|olive|black|darkgray|gray|lightgray|white or an SVG color name"
return return
self.app.painter.set_color(color) self.app.painter.set_color(color)
@@ -383,6 +378,22 @@ class Command_prompt(Label):
return return
self.app.painter.set_grid(mesh) self.app.painter.set_grid(mesh)
# set zoom level (changes size of elements)
def run_set_zoom(self,argv):
if len(argv)==2:
self.message="error: missing argument in 'set zoom'"
return
else:
try:
zoom_level=float(argv[2])
except:
self.message="error: unrecognized argument '"+argv[2]+"' -- usage 'set zoom <zoom_level>'"
return
if zoom_level<0:
self.message="error: zoom level cannot be negative: '"+argv[2]+"'"
return
self.app.painter.set_zoom(zoom_level)
# write to file # write to file
@@ -443,3 +454,21 @@ class Command_prompt(Label):
self.app.openfile=argv[1] self.app.openfile=argv[1]
# update status bar # update status bar
self.app.status_bar.draw() self.app.status_bar.draw()
# export to file in Tikz format
def run_export(self,argv):
if len(argv)>2:
self.message="error: could not open file: too many arguments -- usage: ':export <path to file>'"
return
elif len(argv)==1:
self.message="error: could not open file: no argument found -- usage: ':export <path to file>'"
return
# check that the file can be edited
(ret,self.message)=filecheck.check_edit(argv[1])
# error
if ret<0:
return
# export
self.app.painter.export_tikz(argv[1])

View File

View File

View File

@@ -10,6 +10,8 @@ from polyomino import Square_element
from tools import remove_fromlist from tools import remove_fromlist
import colors
# painter class # painter class
class Painter(Widget): class Painter(Widget):
@@ -29,6 +31,9 @@ class Painter(Widget):
# relative position of mouse when moving # relative position of mouse when moving
self.offset=Point(0,0) self.offset=Point(0,0)
# reference particle from which positions should be computed
self.reference=None
# app is used to share information between widgets # app is used to share information between widgets
self.app=app self.app=app
@@ -40,7 +45,7 @@ class Painter(Widget):
# init keyboard # init keyboard
self.keyboard = Window.request_keyboard(None,self,"text") self.keyboard = Window.request_keyboard(None,self,"text")
self.keyboard.bind(on_key_down=self.on_key_down,on_key_up=self.on_key_up) self.keyboard.bind(on_key_down=self.on_key_down,on_key_up=self.on_key_up,on_textinput=self.on_textinput)
def reset(self): def reset(self):
@@ -48,19 +53,36 @@ class Painter(Widget):
self.undermouse=None self.undermouse=None
self.draw() self.draw()
# convert logical coordinates (normalized and centered) to the ones that are plotted
def pos_tocoord_x(self,x):
return self.width/2+x*Square_element.size
def pos_tocoord_y(self,y):
return self.height/2+y*Square_element.size
def coord_topos_x(self,x):
return (x-self.width/2)/Square_element.size
def coord_topos_y(self,y):
return (y-self.height/2)/Square_element.size
# draw all particles # draw all particles
def draw(self): def draw(self):
self.canvas.clear() self.canvas.clear()
with self.canvas: with self.canvas:
# draw order: particles, then grids, then transparent particles
for particle in self.particles:
particle.draw(self)
# draw grids # draw grids
for particle in self.particles: for particle in self.particles:
if particle.grid>0: if particle.grid>0:
self.draw_grid(particle.squares[0].pos,particle.grid) self.draw_grid(particle.squares[0].pos,particle.grid)
for particle in self.particles: for particle in self.particles:
particle.draw() particle.draw(self,alpha=0.5)
# draw a grid around a particle
def draw_grid(self,pos,mesh): def draw_grid(self,pos,mesh):
# height offset due to status bar and command prompt # height offset due to status bar and command prompt
height_offset=self.app.status_bar.height+self.app.command_prompt.height height_offset=self.app.status_bar.height+self.app.command_prompt.height
@@ -80,7 +102,7 @@ class Painter(Widget):
# respond to keyboard # respond to keyboard
def on_key_down(self, keyboard, keycode, text, modifiers): def on_key_down(self, keyboard, keycode, text, modifiers):
# check that command_prompt is not focused # check the command_prompt is not focused
if not self.app.command_prompt.insert: if not self.app.command_prompt.insert:
if keycode[1]=="shift": if keycode[1]=="shift":
if not 's' in self.modifiers: if not 's' in self.modifiers:
@@ -93,8 +115,12 @@ class Painter(Widget):
self.selected=[] self.selected=[]
self.draw() self.draw()
# respond to keyboard (text input is modifier-sensitive, i.e. one can use shift)
def on_textinput(self, window, text):
# check the command_prompt is not focused
if not self.app.command_prompt.insert:
# select all # select all
elif keycode[1]=="a": if text=="a":
for particle in self.particles: for particle in self.particles:
particle.selected=True particle.selected=True
self.selected=self.particles.copy() self.selected=self.particles.copy()
@@ -102,7 +128,7 @@ class Painter(Widget):
self.draw() self.draw()
# toggle grid # toggle grid
elif keycode[1]=="g": elif text=="g":
for particle in self.selected: for particle in self.selected:
if particle.grid==0: if particle.grid==0:
particle.grid=1 particle.grid=1
@@ -110,6 +136,25 @@ class Painter(Widget):
particle.grid=-particle.grid particle.grid=-particle.grid
self.draw() self.draw()
# zoom
elif text=="+":
# increment by 10%
self.set_zoom(Square_element.size/50*1.1)
elif text=="-":
# decrease by 10%
self.set_zoom(Square_element.size/50*0.9)
elif text=="=":
# reset
self.set_zoom(1)
# set reference
elif text=="r":
if len(self.selected)>0:
self.reference=self.selected[0]
else:
self.reference=None
self.app.status_bar.draw()
def on_key_up(self, keyboard, keycode): def on_key_up(self, keyboard, keycode):
if keycode[1]=="shift": if keycode[1]=="shift":
if 's' in self.modifiers: if 's' in self.modifiers:
@@ -123,10 +168,13 @@ class Painter(Widget):
def on_touch_down(self,touch): def on_touch_down(self,touch):
# only respond to touch in drawing area # only respond to touch in drawing area
if self.collide_point(*touch.pos): if self.collide_point(*touch.pos):
# convert to logical
touchx=self.coord_topos_x(touch.x)
touchy=self.coord_topos_y(touch.y)
# create new cross # create new cross
if touch.button=="right": if touch.button=="right":
new=Cross(touch.x/Square_element.size,touch.y/Square_element.size) new=Cross(touchx,touchy)
if not self.check_interaction_any(new,Point(0,0)): if not self.check_interaction_any(new,Point(0,0)):
# add to list # add to list
self.particles.append(new) self.particles.append(new)
@@ -142,11 +190,11 @@ class Painter(Widget):
# select particle # select particle
if touch.button=="left": if touch.button=="left":
# find particle under touch # find particle under touch
self.undermouse=self.find_particle(Point(touch.x/Square_element.size,touch.y/Square_element.size)) self.undermouse=self.find_particle(Point(touchx,touchy))
# record relative position of click with respect to reference # record relative position of click with respect to reference
if self.undermouse!=None: if self.undermouse!=None:
self.offset=Point(touch.x/Square_element.size,touch.y/Square_element.size)-self.undermouse.squares[0].pos self.offset=Point(touchx,touchy)-self.undermouse.squares[0].pos
# no modifiers # no modifiers
if self.modifiers==[]: if self.modifiers==[]:
@@ -183,21 +231,31 @@ class Painter(Widget):
self.draw() self.draw()
# draw status bar
self.app.status_bar.draw()
# respond to drag # respond to drag
def on_touch_move(self,touch): def on_touch_move(self,touch):
# convert to logical
touchx=self.coord_topos_x(touch.x)
touchy=self.coord_topos_y(touch.y)
# only respond to touch in drawing area # only respond to touch in drawing area
if self.collide_point(*touch.pos): if self.collide_point(*touch.pos):
# only move on left click # only move on left click
if touch.button=="left" and self.modifiers==[] and self.undermouse!=None: if touch.button=="left" and self.modifiers==[] and self.undermouse!=None:
# attempted move determined by the relative position to the relative position of click within self.undermouse # attempted move determined by the relative position to the relative position of click within self.undermouse
delta=self.adjust_move(Point(touch.x/Square_element.size,touch.y/Square_element.size)-(self.offset+self.undermouse.squares[0].pos),0) delta=self.adjust_move(Point(touchx,touchy)-(self.offset+self.undermouse.squares[0].pos),0)
for particle in self.selected: for particle in self.selected:
particle.move(delta) particle.move(delta)
# redraw # redraw
self.draw() self.draw()
# draw status bar
self.app.status_bar.draw()
# find the particle at position pos # find the particle at position pos
def find_particle(self,pos): def find_particle(self,pos):
@@ -414,6 +472,41 @@ class Painter(Widget):
ff.close() ff.close()
self.draw() self.draw()
# export to tikz
def export_tikz(self,file):
# abort if no particles
if len(self.particles)==0:
return
ff=open(file,"w")
# header
ff.write("\documentclass{standalone}\n")
ff.write("\n")
ff.write("\\usepackage[svgnames]{xcolor}\n")
ff.write("\\usepackage{tikz}\n")
ff.write("\\usepackage{jam}\n")
ff.write("\n")
ff.write("\\begin{document}\n")
ff.write("\\begin{tikzpicture}\n")
ff.write("\n")
# write position of particles
for particle in self.particles:
if type(particle)==Cross:
ff.write("\cross{"+colors.closest_color(particle.color,colors.xcolor_names)+"}")
ff.write("{{({:05.2f},{:05.2f})}};\n".format(particle.squares[0].pos.x-self.particles[0].squares[0].pos.x,particle.squares[0].pos.y-self.particles[0].squares[0].pos.y))
ff.write("\\end{tikzpicture}\n")
ff.write("\\end{document}\n")
ff.write("\n")
ff.close()
# set zoom level
def set_zoom(self,level):
Square_element.size=level*50
self.draw()
# global variables (used like precompiler variables) # global variables (used like precompiler variables)
CROSS_INDEX=1 CROSS_INDEX=1

View File

@@ -18,32 +18,37 @@ class Polyomino():
self.grid=kwargs.get("grid",0) self.grid=kwargs.get("grid",0)
# draw function # draw function
def draw(self): def draw(self,painter,**kwargs):
alpha=kwargs.get("alpha",1)
# set color # set color
if not self.selected: if not self.selected:
Color(*self.color) Color(*self.color,alpha)
else: else:
(r,g,b)=self.color (r,g,b)=self.color
# darken selected # darken selected
Color(r/2,g/2,b/2) Color(r/2,g/2,b/2,alpha)
for square in self.squares: for square in self.squares:
Rectangle(pos=((square.pos.x-0.5)*square.size,(square.pos.y-0.5)*square.size),size=(square.size,square.size)) Rectangle(pos=(painter.pos_tocoord_x(square.pos.x-0.5),painter.pos_tocoord_y(square.pos.y-0.5)),size=(square.size,square.size))
# draw boundary # draw boundary
self.stroke() self.stroke(painter)
# draw boundary (override for connected polyominos) # draw boundary (override for connected polyominos)
def stroke(self): def stroke(self,painter):
# convert to graphical coordinates
coordx=painter.pos_tocoord_x(square.pos.x)
coordy=painter.pos_tocoord_y(square.pos.y)
# white # white
Color(1,1,1) Color(1,1,1)
for square in self.squares: for square in self.squares:
Line(points=( Line(points=(
*((square.pos.x-0.5)*square.size,(square.pos.y-0.5)*square.size), *(coordx-0.5*square.size,coordy-0.5*square.size),
*((square.pos.x-0.5)*square.size,(square.pos.y+0.5)*square.size), *(coordx-0.5*square.size,coordy+0.5*square.size),
*((square.pos.x+0.5)*square.size,(square.pos.y+0.5)*square.size), *(coordx+0.5*square.size,coordy+0.5*square.size),
*((square.pos.x+0.5)*square.size,(square.pos.y-0.5)*square.size), *(coordx+0.5*square.size,coordy-0.5*square.size),
*((square.pos.x-0.5)*square.size,(square.pos.y-0.5)*square.size) *(coordx-0.5*square.size,coordy-0.5*square.size)
)) ))
# move by delta # move by delta
@@ -83,22 +88,26 @@ class Cross(Polyomino):
]) ])
# redefine stroke to avoid lines between touching squares # redefine stroke to avoid lines between touching squares
def stroke(self): def stroke(self,painter):
# convert to graphical coordinates
coordx=painter.pos_tocoord_x(self.squares[0].pos.x)
coordy=painter.pos_tocoord_y(self.squares[0].pos.y)
Color(1,1,1) Color(1,1,1)
Line(points=( Line(points=(
*((self.squares[0].pos.x-0.5)*Square_element.size,(self.squares[0].pos.y-0.5)*Square_element.size), *(coordx-0.5*Square_element.size,coordy-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), *(coordx-0.5*Square_element.size,coordy-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), *(coordx+0.5*Square_element.size,coordy-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), *(coordx+0.5*Square_element.size,coordy-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), *(coordx+1.5*Square_element.size,coordy-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), *(coordx+1.5*Square_element.size,coordy+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), *(coordx+0.5*Square_element.size,coordy+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), *(coordx+0.5*Square_element.size,coordy+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), *(coordx-0.5*Square_element.size,coordy+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), *(coordx-0.5*Square_element.size,coordy+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), *(coordx-1.5*Square_element.size,coordy+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), *(coordx-1.5*Square_element.size,coordy-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), *(coordx-0.5*Square_element.size,coordy-0.5*Square_element.size),
)) ))

View File

@@ -39,5 +39,15 @@ class Status_bar(Label):
if self.app.readonly: if self.app.readonly:
self.raw_text+=" [RO]" self.raw_text+=" [RO]"
# coordinates of selected cross
if len(self.app.painter.selected)>0:
# number of spaces to align right (use 13 characters to print position)
spaces=int(self.width/self.char_width)-len(self.raw_text)-13
if spaces>0:
if self.app.painter.reference==None:
self.raw_text+=" "*spaces+"({:05.2f},{:05.2f})\n".format(self.app.painter.selected[0].squares[0].pos.x,self.app.painter.selected[0].squares[0].pos.y)
else:
self.raw_text+=" "*spaces+"({:05.2f},{:05.2f})\n".format(self.app.painter.selected[0].squares[0].pos.x-self.app.painter.reference.squares[0].pos.x,self.app.painter.selected[0].squares[0].pos.y-self.app.painter.reference.squares[0].pos.y)
# do not wrap # do not wrap
self.text=self.raw_text[:min(len(self.raw_text),int(self.width/self.char_width))] self.text=self.raw_text[:min(len(self.raw_text),int(self.width/self.char_width))]