def __init__(self, json): if JSONParser._parser(json) == 1: raise ValueError("Bad json") shapes = [] self.screen = dict() self.palette = dict() for i in json["Palette"]: self.palette[i] = JSONParser.return_color(dict(), json["Palette"][i]) self.screen["width"] = json["Screen"]["width"] self.screen["height"] = json["Screen"]["height"] self.screen["bg_color"] = JSONParser.return_color( self.palette, json["Screen"]["bg_color"]) self.screen["fg_color"] = JSONParser.return_color( self.palette, json["Screen"]["fg_color"]) for i in json["Figures"]: type = i["type"] if type == "point": if "color" in i: color = JSONParser.return_color(self.palette, i["color"]) else: color = self.screen["fg_color"] shapes.append(Shape.Point(i["x"], i["y"], color)) elif type == "polygon": if "color" in i: color = JSONParser.return_color(self.palette, i["color"]) else: color = self.screen["fg_color"] shapes.append(Shape.Polygon(i["points"], color)) elif type == "rectangle": if "color" in i: color = JSONParser.return_color(self.palette, i["color"]) else: color = self.screen["fg_color"] shapes.append( Shape.Rectangle(i["x"], i["y"], i["width"], i["height"], color)) elif type == "square": if "color" in i: color = JSONParser.return_color(self.palette, i["color"]) else: color = self.screen["fg_color"] shapes.append(Shape.Square(i["x"], i["y"], i["size"], color)) elif type == "circle": if "color" in i: color = JSONParser.return_color(self.palette, i["color"]) else: color = self.screen["fg_color"] shapes.append( Shape.Circle(i["x"], i["y"], i["radius"], color=color)) else: print("Bad type of figure") raise ValueError("Bad type of figure") self.shapes = shapes
inScreenSpace, pos = engine.GetMouseScreenPos() if inScreenSpace: engine.PieceList = [ Shape.Piece([0, 0], [1, 1], points + [pos], [255, 255, 255]) ] else: engine.PieceList = [ Shape.Piece([0, 0], [1, 1], points, [255, 255, 255]) ] engine.PieceList += [ Shape.Piece([350, 350], [100, 100], objectPoints, [255, 255, 255]) ] if len(objectPoints) > 2: engine.PieceList += [ Shape.Piece([350, 350], [100, 100], Shape.Square(), [255, 0, 0]) ] engine.PieceList += [ Shape.Piece([350, 350], [100, 100], objectPoints, [255, 255, 255]) ] if mouse.is_pressed(button="left") and not leftClickDown: inScreenSpace, pos = engine.GetMouseScreenPos() if inScreenSpace: points += [pos] leftClickDown = True elif not mouse.is_pressed(button="left"): leftClickDown = False