import json def setup(): size(500, 500) stroke(50, 50, 250) fill(150, 150, 250) rectMode(CENTER) global creatures try: f = open("creatures.json","r") file_contents = f.read() creatures = json.loads(file_contents) except IOError: creatures = [] def draw(): background(255) i = 0 while i <= len(creatures)-1: creature = creatures[i] fill( creature["r"], creature["g"], creature["b"]) rect(creature["x"], creature["y"], 25, 25) creature["x"] = creature["x"] + random(-5,5) creature["y"] = creature["y"] + random(-5,5) i = i + 1 def stop(): print("Goodbye") creatures_text = json.dumps(creatures) f = open("creatures.json","w") f.write(creatures_text) f.close() def mousePressed(): tmp_dict = {} tmp_dict["x"] = mouseX tmp_dict["y"] = mouseY tmp_dict["r"] = random(0,255) tmp_dict["g"] = random(0,255) tmp_dict["b"] = random(0,255) creatures.append(tmp_dict)