From b1d56fea0484f973c367bfa6b40e3fed34172f32 Mon Sep 17 00:00:00 2001 From: Ian Jauslin Date: Wed, 21 Feb 2024 15:30:52 -0500 Subject: [PATCH] Set shape from command --- src/command_prompt.py | 19 ++++++++++++++++++- src/painter.py | 6 ++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/command_prompt.py b/src/command_prompt.py index 7bbe4b1..9c5569d 100644 --- a/src/command_prompt.py +++ b/src/command_prompt.py @@ -20,6 +20,7 @@ import os.path import filecheck import colors +from polyomino import Cross,Disk class Command_prompt(Label): @@ -338,6 +339,9 @@ class Command_prompt(Label): if argv[1]=="color": self.run_set_color(argv) return + elif argv[1]=="shape": + self.run_set_shape(argv) + return elif argv[1]=="grid": self.run_set_grid(argv) return @@ -350,7 +354,7 @@ class Command_prompt(Label): # set color def run_set_color(self,argv): if len(argv)<3: - self.message="error: 'set color' command was run with without anargument -- usage: 'set color '" + self.message="error: 'set color' command was run with without an argument -- usage: 'set color '" return # find color name in list for color in colors.xcolor_names: @@ -372,6 +376,19 @@ class Command_prompt(Label): return self.app.painter.set_color(color) + # set particle shape + def run_set_shape(self,argv): + if len(argv)<3: + self.message="error: 'set shape' command was run with without an argument -- usage: 'set shape '" + return + elif argv[2]=="cross": + self.app.painter.shape=Cross + elif argv[2]=="disk": + self.app.painter.shape=Disk + else: + self.message="error: unrecognized shape '"+argv[2]+"'; supported shapes are cross|disk" + return + # toggle grid def run_set_grid(self,argv): if len(argv)==2: diff --git a/src/painter.py b/src/painter.py index 4f0e34d..b38050f 100644 --- a/src/painter.py +++ b/src/painter.py @@ -35,6 +35,9 @@ class Painter(Widget): # list of particles self.particles=[] + # shape of particle to add next + self.shape=Cross + # underlying lattice self.lattice=None @@ -229,8 +232,7 @@ class Painter(Widget): # create new particle if touch.button=="right": - new=Cross(touchx,touchy) - #new=Disk(touchx,touchy) + new=self.shape(touchx,touchy) # snap to lattice if self.lattice!=None: new.move(self.lattice.nearest_delta(new.elements[0].pos))