Set shape from command
This commit is contained in:
parent
955aa8f10a
commit
b1d56fea04
@ -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
|
||||
@ -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 <shape_descriptor>'"
|
||||
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:
|
||||
|
@ -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))
|
||||
|
Loading…
Reference in New Issue
Block a user