set color

This commit is contained in:
Ian Jauslin 2021-12-01 14:23:21 -05:00
parent 26e76a3699
commit c17226cd44
2 changed files with 61 additions and 2 deletions

View File

@ -295,6 +295,11 @@ class Command_prompt(Label):
# parse command line # parse command line
self.parse_argv() self.parse_argv()
# commands that cannot be compounded
if self.argv[0]=="set":
self.run_set(self.argv)
return
# single letter commands (which can be combined) # single letter commands (which can be combined)
# write # write
if self.argv[0]=="w" or self.argv[0]=="w!" or self.argv[0]=="wq": if self.argv[0]=="w" or self.argv[0]=="w!" or self.argv[0]=="wq":
@ -306,7 +311,53 @@ class Command_prompt(Label):
if self.argv[0]=="q" or self.argv=="wq": if self.argv[0]=="q" or self.argv=="wq":
self.app.stop() self.app.stop()
# wrie to file # set properties of particles
def run_set(self,argv):
if len(argv)<3:
self.message="error: 'set' command was run with too few arguments -- usage: 'set <property> <value>'"
return
if argv[1]=="color":
self.run_set_color(argv)
return
else:
self.message="error: unrecognized command '"+argv[1]+"'"
return
def run_set_color(self,argv):
if argv[2]=="blue":
self.app.painter.set_color((0,0,1))
elif argv[2]=="green":
self.app.painter.set_color((0,1,0))
elif argv[2]=="red":
self.app.painter.set_color((1,0,0))
elif argv[2]=="cyan":
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(",")
# error if improperly formatted
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"
return
try:
color=(float(color_str[0]),float(color_str[1]),float(color_str[2]))
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"
return
self.app.painter.set_color(color)
# write to file
def run_write(self,argv): def run_write(self,argv):
if len(argv)>2: if len(argv)>2:
self.message="error: could not write to file: too many arguments -- usage: ':w [path to file]'" self.message="error: could not write to file: too many arguments -- usage: ':w [path to file]'"
@ -335,6 +386,7 @@ class Command_prompt(Label):
# update status bar # update status bar
self.app.status_bar.draw() self.app.status_bar.draw()
# edit file
def run_edit(self,argv): def run_edit(self,argv):
if len(argv)>2: if len(argv)>2:
self.message="error: could not open file: too many arguments -- usage: ':e <path to file>'" self.message="error: could not open file: too many arguments -- usage: ':e <path to file>'"
@ -363,4 +415,3 @@ 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()

View File

@ -250,6 +250,14 @@ class Painter(Widget):
return self.adjust_move_element(newdelta,element,recursion_depth+1) return self.adjust_move_element(newdelta,element,recursion_depth+1)
# set color of selected particles
def set_color(self,color):
for particle in self.selected:
particle.color=color
# redraw
self.draw()
# write configuration to file # write configuration to file
def write(self,file): def write(self,file):
ff=open(file,"w") ff=open(file,"w")