read/write disks

This commit is contained in:
Ian Jauslin 2022-09-27 19:13:44 -04:00
parent c2ebf92a0e
commit dd5917cd45

View File

@ -450,6 +450,8 @@ class Painter(Widget):
for particle in self.particles: for particle in self.particles:
if type(particle)==Cross: if type(particle)==Cross:
ff.write("{:d};".format(CROSS_INDEX)) ff.write("{:d};".format(CROSS_INDEX))
elif type(particle)==Disk:
ff.write("{:d};".format(DISK_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()
@ -527,6 +529,8 @@ class Painter(Widget):
continue continue
if particle_type==CROSS_INDEX: if particle_type==CROSS_INDEX:
candidate=Cross(pos.x,pos.y,color=color) candidate=Cross(pos.x,pos.y,color=color)
elif particle_type==DISK_INDEX
candidate=Disk(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
@ -579,5 +583,6 @@ class Painter(Widget):
# global variables (used like precompiler variables) # global variables (used like precompiler variables)
CROSS_INDEX=1 CROSS_INDEX=1
DISK_INDEX=2